I have written a macro that calls three other macros inside of it in order to use a public variable in the 3 macros . The macro runs perfectly from excel but when I try and call the macro in power shell I receive an error message.
Here is the macro that works perfectly in excel:
Public Fnum As Integer
Sub master_macro()
combine_workbooks
automate_search
delete_duplicate
End Sub
here is the powershell code:
#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()
finally here is the error message i receive when the powershell is run:
Exception calling "Run" with "31" argument(s): "Cannot run the macro 'delete_duplicates'. The macro may not be availabl e in this workbook or all macros may be disabled." At C:\File Build Project\Testing\PowerShellScript_Test_automation.ps1:17 char:11 + $excel.Run <<<< ("delete_duplicates") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
Any Help would be appreciated
delete_duplicate
, but your error message saysdelete_duplicates
(note the finals
). According to your code snippet,delete_duplicates
is not available when runningmaster_macro
. – Ken White yesterdayApplication.Run
rondebruin.nl/win/s9/win001.htm – Tim Williams yesterday