在任何PATH上执行prgram

时间:2017-09-28 18:54:35

标签: python excel

我正在尝试使用excel执行程序。但它只适用于我的电脑。有多个用户使用不同的计算机。有没有办法让python在某人的计算机上搜索该文件,并将该路径保存到下面显示的xls路径代码中。我尝试使用shutil但我收到了我自己目录的权限被拒绝错误消息。我正在寻找的文件是Ten Year Load Forecasts 2017-2026.xlsm。共有3个驱动器:F:\C:\I:\。此外,如果用户将Excel工作表保存到多个区域,它如何区分需要读取的文件。

xlApp = win32com.client.DispatchEx('Excel.Application') # Running Excel
xlsPath = os.path.expanduser('I:\TPGeneral\Ten Year Load Forecasts 2017-2026.xlsm')# Reading xlsm file
wb = xlApp.Workbooks.Open(Filename=xlsPath) # Opening file
xlApp.Run('csvfile2')# Running macro---- csvfile2 is the macro name. It is under the "csv" module in the VBA editor
wb.Save()
xlApp.Quit()

0 个答案:

没有答案