ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Running a macro from windows application (https://www.excelbanter.com/excel-discussion-misc-queries/204910-running-macro-windows-application.html)

Aerojade

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.

Thanks


Dave Peterson

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


All times are GMT +1. The time now is 11:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com