我编写了一个宏来调用其中的三个其他宏,以便在3个宏中使用公共变量。宏从excel运行完美,但是当我尝试在power shell中调用宏时,我收到一条错误消息。
这是在excel中完美运行的宏:
Public Fnum As Integer
Sub master_macro()
combine_workbooks
automate_search
delete_duplicate
End Sub
这是powershell代码:
#PowerShellScript to Test automation of 80% test
# start Excel
$excel = New-Object -comobject Excel.Application
#open file
$FilePath = 'C:\File Build Project\!Notes for FileBuild Project\PF PM Data Collection Workbook-template Our Macro'
$workbook = $excel.Workbooks.Open($FilePath)
#no point to see excel since everything else is shutdown in vba
$excel.Visible = $False
$excel.DisplayAlerts = $False
#run macro save workbook close excel
$excel.Run("master_macro")
$workbook.Save()
$excel.quit()
最后这是运行powershell时收到的错误消息:
使用“31”参数调用“Run”的异常:“无法运行宏'delete_duplicates'。宏可能无法使用 e在此工作簿中或所有宏都可能被禁用。“ 在C:\ File Build Project \ Testing \ PowerShellScript_Test_automation.ps1:17 char:11 + $ excel.Run<<<< ( “delete_duplicates”) + CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:DotNetMethodException
任何帮助将不胜感激