1

My code is below. BUt i am getting error

xlapp = win32com.client.gencache.EnsureDispatch("Excel.Application")
xlapp.Interactive = False
xlapp.Application.EnableEvents = False
xlapp.DisplayAlerts = False  # Suppress any Alert windows, which require User action
xlapp.AskToUpdateLinks = False  # Disable automatic update linking
xlapp.Visible = False  # Run the Application in the background

pathname = os.path.dirname(destination_file)
path = os.path.abspath(pathname) + '\\'
out_file = path + destination_file

print(f"The outfile path is {out_file}")

# Open the workbook in said instance of Excel
wb_7 = xlapp.workbooks.open(out_file)

# Refresh all data connections.
wb_7.RefreshAll()
xlapp.CalculateUntilAsyncQueriesDone()
wb_7.Save()
wb_7.Close(True)
wb_7 = None  # Unset wb_7 variable (This is to ensure it's closed)

xlapp.Interactive = True
xlapp.DisplayAlerts = True  # Suppress any Alert windows, which require User action
xlapp.AskToUpdateLinks = True  # Disable automatic update linking
xlapp.Application.EnableEvents = True
xlapp.Visible = True  # Run the Application in the background
xlapp.Quit()  # Close Excel

i am getting the below error... couldnt able to get what i need to fix here i need some suggestion

raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
AttributeError: '<win32com.gen_py.Microsoft Excel 16.0 Object Library._Application instance at 
0x2584370933424>' object has no attribute 'workbooks'
0

1 Answer 1

2

win32 objects are Case sensitive, so would need to capitalize.

wb_7 = xlapp.workbooks.open(out_file)

would need to be

wb_7 = xlapp.Workbooks.Open(out_file)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.