View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Running a macro from windows application

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

'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).


Aerojade wrote:

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.

Thanks


--

Dave Peterson