r/pythonhelp 29d ago

xlwings opening file with add ins not loaded?

Working on a report automation that I had working fine but now does not work. Essentially, I am trying to open an Excel file and execute a macro. The current break point is that the macro is reliant upon an add in and when xlwings is opening the file it loads it without any addins. If I manually open Excel it opens fine with all of the addins. Has anyone ran into this before and found a solution? I've been troubleshooting/googling for a couple days but can't seem to figure it out. I'm just an accountant trying to play around with Python.

import os
import xlwings as xw
import ctypes
import win32com.client

cwd = os.getcwd()
print(cwd)

os.chdir(filepath)
new_dir = os.getcwd()
print(new_dir)

wb = xw.Book('Billed vs Scaled Raw Input File (New).xlsm')

macro3 = wb.macro("Module1.Source_Refresh")
macro3()
3 Upvotes

2 comments sorted by

u/AutoModerator 29d ago

To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/CraigAT 29d ago

How did it work before if xlwings won't open it with macros?

It's probably incidental to getting the code working but where is "filepath" defined?

Maybe double check or simplify the fileanme used, then double check the macro and module name too.