How to use python win32com to save as excel file

fk. picture fk. · Nov 16, 2009 · Viewed 21k times · Source

I have a small python code to open an Excel file. Now I want to "Save As" with a different name but same format. How do I do that.. Any help will be great. FK

Answer

EkaterinaSS picture EkaterinaSS · Jan 10, 2021

Just use \\ instead of /

import win32com.client 

office = win32com.client.Dispatch("Excel.Application") 
wb = office.Workbooks.Open("C:/FileName.xlsx") 
wb.SaveAs(Filename:="C:\\NewFileName.xlsx")
wb.Close()
office.Quit()