ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Calling an XLA macro from code (https://www.excelbanter.com/excel-programming/279313-calling-xla-macro-code.html)

Chrissy[_4_]

Calling an XLA macro from code
 
How do I call an XLA macro from the code in another workbook?

Chrissy.



keepITcool

Calling an XLA macro from code
 
Step1:

make sure the CALLED procedures:
are NOT private.
are NOT located in object modules (like thisworkbook or Sheet1)
are NOT located in module with OPTION PRIVATE MODULE

THEN
EITHER

use the RUN method to run the macro.

OR make a fixed reference to it:
in the VBE: give the Addin's VBAProject a meaningfull name.
by clicking on it in the ProjExplorer and Changing it's name in the
Properties window. E.g. TESTADDIN

THEN
in the VBE Tools/References Checkmark the XXX.xla in the list
then close.

this way you can call the procedures and you'll find the procedures
in the object browser with the linking workbook active.

EXAMPLES:
'CODE FOR CALLER.xls SHEET1 object module
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
'This works when the book has a REFERENCE to TESTaddin
Call showmsg(Target.Address)
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Run "test.xla!showmsg", Target.Address
End Sub

'CODE FOR TEST.XLA Module1
Sub ShowMsg(sMsg As String)
MsgBox sMsg
End Sub


HTH :)


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Chrissy" wrote:

How do I call an XLA macro from the code in another workbook?

Chrissy.





Tim Zych[_4_]

Calling an XLA macro from code
 
Just to add...

Application.Run "Addin.xla!Mcr"

or if there are spaces in the book name:

Application.Run "'Addin 2.xla'!Mcr"

or if apostrophes/spaces:

Application.Run "'" & Replace("Addin's.xla", "'", "''") & "'!Mcr"


"Chrissy" wrote in message
...
How do I call an XLA macro from the code in another workbook?

Chrissy.






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

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