Running a macro from windows application



I need to run an Excel macro that is contained in the "ThisWorkbook" Module
of the file from a windows application. Can this be done. If so ...please
help me out with the code.

I tried OBJExcelWorkbook.Application.Run("MyMacro",missing,missing......)
but it says macro cant be found. I think this is because it is inside
"ThisWorkbook". Please help.


Dave Peterson

This is how I would do it in VBA (from within excel and from within the same

'inside the ThisWorkbook module
'notice the Public keyword
Option Explicit
Public Sub myMacro(str1 As String, str2 As String)
MsgBox str1 & vbLf & str2
End Sub

And from a General module:
Option Explicit
Sub testme()
Application.Run "thisworkbook.mymacro", "asdf", "qwer"
End Sub

Actually, I would try to put any subroutine that isn't a workbook event in a
general module (well, most the time).

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question