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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,826
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Perhaps you could share the solution in case someone else has a similar issue?
 

Forum statistics

Threads
1,148,294
Messages
5,745,936
Members
423,985
Latest member
sayed manzar

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
Top