View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default 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.