Reputation: 63
Using xlwings I want to save an Excel workbook with a different name in a different directory. Numerous attempts, including advice offered in this forum, have not worked.
import xlwings as xw
path1 = 'mine/path1/'
path2 = 'mine/path2/'
app = xw.App() # including this line does not help
wb = xw.Book(path1 + 'XXX.xlsx')
wb.save() # this works as expected
wb.save(path1 + 'YYY.xlsx') # this doesn't work
wb.save(path2 + 'YYY.xlsx') # neither does this
Error message running the last line (second last commented out):
C:\tools\Anaconda3\envs\valenv\python.exe C:/Users/Owner/PycharmProjects/FIIG/stuff.py Traceback (most recent call last):
File "C:\Users\Owner\PycharmProjects\FIIG\stuff.py", line 32, in wb.save(path5 + 'XXX.xlsx')
File "C:\tools\Anaconda3\envs\valenv\lib\site-packages\xlwings\main.py", line 740, in save self.impl.save(path)
File "C:\tools\Anaconda3\envs\valenv\lib\site-packages\xlwings_xlwindows.py", line 552, in save self.xl.SaveAs(os.path.realpath(path), FileFormat=file_format)
File "C:\tools\Anaconda3\envs\valenv\lib\site-packages\xlwings_xlwindows.py", line 66, in call v = self.__method(*args, **kwargs)
File "C:\Users\Owner\AppData\Local\Temp\gen_py\3.9\00020813-0000-0000-C000-000000000046x0x1x9.py", line 46793, in SaveAs return self.oleobj.InvokeTypes(3174, LCID, 1, (24, 0), ((12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (3, 49), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17)),Filename pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
Upvotes: 0
Views: 2406
Reputation: 1
I have had this issue with xlwings before and the fix I came to was to shorten the length of the filename I was saving.
Upvotes: 0
Reputation: 7070
I can't replicate this. This works for me with xlwings 0.23.1:
import xlwings as xw
path1 = 'C:/Users/felix/Desktop/'
wb = xw.Book(path1 + 'Book1.xlsx')
wb.save(path1 + 'YYY.xlsx')
Upvotes: 0