According to the error message, the.xlsm file requested by the Python script cannot be opened because it is being used by another process. This may occur if another application is using the file or if the file is already open in an instance of Excel.
Try closing all instances of Excel and any other programmes that could be utilising the file in order to fix this problem. After that, try rerunning the Python script to see whether the issue persists.
You might try utilising the openpyxl library as an all-in-one library for data analysis on.xlsm files. You may read, write, and execute different data analysis activities on Excel files, including.xlsm files, with this library. Moreover, managing macros and VBA code in Excel files is well supported. Here is an illustration of how to read an.xlsm file using openpyxl:
import openpyxl
import pandas as pd
wb = openpyxl.load_workbook('file.xlsm', read_only=True, keep_vba=True)
ws = wb['Sheet1']
data = []
for row in ws.iter_rows(values_only=True):
data.append(row)
df = pd.DataFrame(data, columns=['Column1', 'Column2', 'Column3'])
wb.close()