Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
Your code says delete_duplicate, but your error message says delete_duplicates (note the final s). According to your code snippet, delete_duplicates is not available when running master_macro. – Ken White yesterday
2  
Need to include the file name when using Application.Run rondebruin.nl/win/s9/win001.htm – Tim Williams yesterday

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.