-
-
Save garymanley/d6ff66218747d4463af921588226a722 to your computer and use it in GitHub Desktop.
Open and Close Xlwings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xlwings as xw | |
import glob | |
import os | |
import datetime | |
### Not needed for this script but is used in many others | |
import win32com.client | |
### set whether to run this section | |
Excel = True | |
### run this section | |
if Excel: | |
### Get list of files matching the basic file name | |
list_of_files = glob.glob('File Location\\Filename*.xlsx') | |
### get the latest file | |
latest_file = max(list_of_files, key=os.path.getctime) | |
### Set XLwings app to visible - I had a problem with this so just to be sure | |
xw.App(visible=True) | |
### Open the latest file | |
wb = xw.Book(latest_file) | |
### Select the Sheet, Sheet Name | |
wb.sheets['Sheet Name'].select() | |
### Set Filename to filename with todays date | |
filename = 'Folder Location\\Filename '+datetime.datetime.today().strftime('%d%m%y')+'.xlsx' | |
wb.save(filename) | |
wb.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment