Title error occurs when running python program on VBA.
The error content is PermissionError: Permission denied: 'Excel filename .xlsm'
Thank you for your cooperation.
Here's the code for the VBA.
SubSampleCall()
RunPython("import auto_py; auto_py.textdownload()")")
End Sub
If an Excel file is started, it is prohibited from being read or written by other applications.auto_py
causes that error when accessing a file in the starting Excel.
Generally, you should close the Excel file before you run it, but if the Excel file is one with that VBA
, you cannot close it, so try to avoid it by storing the data on the clipboard before and after the process.
If you want to use a clipboard, it's easy to use Pandas.On the VBA side, do the following:
SubSampleCall()
Range ("A1:E10").Select
Selection.Copy
RunPython("import auto_py; auto_py.textdownload()")")
Range("G1").Select
ActiveSheet.Paste
End Sub
On the Python side, you can easily write as follows:Configure options such as header
as needed.
import pandas as pd
df = pd.read_clipboard()
# treatment
df.to_clipboard()
© 2024 OneMinuteCode. All rights reserved.