【发布时间】:2017-03-25 23:59:52
【问题描述】:
我有一个 Python 程序(如块 1 所示),用于打开一个 Excel 文件并调用一个宏。
Excel 宏(如块 2 所示)打开特定文件夹中的所有 Excel 文件。
Python 程序打开 Excel 文件并调用宏,我已经用不同的文件对其进行了测试,但是当我尝试这个 Excel 文件时,它会打开但宏没有运行。
这里是 Python
from win32com.client import Dispatch
xl = Dispatch('Excel.Application')
wb = xl.Workbooks.Open("K:\\updatebloomberg.xlsm")
xl.Visible = True
wb.Application.Run("'updatebloomberg.xlsm'!Module1.runfiles()")
wb.Close(True)
这里是 VBA
Sub runfiles()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim ws As Worksheet
Dim c As Range
myPath = "K:\Bloomberg Data\"
myExtension = "*.xlsx"
myFile = Dir(myPath & myExtension)
Do While myFile <> ""
Set wb = Workbooks.Open(Filename:=myPath & myFile)
myFile = Dir
Loop
Application.OnTime (Now + TimeValue("00:00:02")), "refreshSheet"
End Sub
【问题讨论】: