Simple powershell script to start macro: not working

Hermanie

Board Regular
Joined
Nov 28, 2016
Messages
56
Hi all,

I have an Excel workbook with 2 modules: OwnMailbox & SharedMailbox. Both modules hold a public sub: OwnMailbox has sub Kickoff, SharedMailbox has sub Kickoff1. I try to start the procedures via PowerShell, however it seems it's not working as expected.

This is working:
Code:
$excel = New-Object -ComObject Excel.Application$excel.Visible = $true
$workbook = $excel.workbooks.open("C:\SaveMail.xlsm")
$xlmodule = $workbook.VBProject.VBComponents.item('SharedMailbox')
$excel.Run('Kickoff1')
$workbook.close($true)
$excel.Quit()

This is not working:
Code:
$excel = New-Object -ComObject Excel.Application$excel.Visible = $true
$workbook = $excel.workbooks.open("C:\SaveMail.xlsm")
$xlmodule = $workbook.VBProject.VBComponents.item('OwnMailbox')
$excel.Run('Kickoff')
$workbook.close($true)
$excel.Quit()

I have no idea why the second routine is not working. It looks like all the functions are the same, the mentioned module and sub procedure is correct but still it's not working. I have the feeling it has something to do with the first module or routine which is in a project. In this case it was 'SharedMailbox'.

Thanks for helping!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Perhaps you could share the solution in case someone else has a similar issue?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top