# Simple powershell script to start macro: not working



## Hermanie (Apr 25, 2018)

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:

```
$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:

```
$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!


----------



## Hermanie (Apr 25, 2018)

Please close thread; error resolved.


----------



## RoryA (Apr 25, 2018)

Perhaps you could share the solution in case someone else has a similar issue?


----------

