Running an addin-macro from another Macro

G

Guest

I have a macro that adds a new addin before saving the file. This macro has
to call/invoke a sub-routine from the addin. I tried using the
application.run but looks like it doesn't work.

Any suggestions?

Thanks
Samir
 
B

Bob Phillips

What did you try, the code?

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)
 
G

Guest

the code as of now is


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim I As Integer
Dim isInstalled As Boolean
Dim dummyVariant As Variant

On Error Resume Next
Application.ScreenUpdating = False
isInstalled = False
'Check whether AddIn is installed...
For I = 1 To AddIns.Count
If Trim(AddIns(I).Name) = "DBUpdater.xla" Then
isInstalled = True
Exit For
End If
Next I

' If not, then install it...
If Not isInstalled Then
' Install from CURRENT directory
AddIns.Add "F:\Finance\Excel\DBUpdater.xla"
Else
' Even if it's installed, it might not be active
If Not AddIns(I).Installed Then AddIns(I).Installed = True
End If

' Now run the damn thing already...
Call pertracupdatefund(ActiveWorkbook.Name)
'dummyVariant = _
Application.Run("DBUpdater.xla!UpdateData", _
ActiveWorkbook.Name)

' Lose the add-ins...
AddIns(I).Installed = False
Application.ScreenUpdating = True

End Sub
 
B

Bob Phillips

Maybe try this

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim oXL As Object
Dim oWB As Workbook
Dim dummyVariant As Variant
Const sXLAPath As String = "F:\Finance\Excel\"
Const sXLA As String = "DBUpdater.xla"
Const sMacro As String = "UpdateData"

On Error Resume Next
Application.ScreenUpdating = False

Set oXL = CreateObject("Excel.Application")
Set oWB = oXL.Workbooks.Open(sXLAPath & sXLA)

' Now run the damn thing already...
dummyVariant = oXL.Run(sXLA & "!" & sMacroActiveWorkbook.Name)

oWB.Close True
Set oWB = Nothing
oXL.Quit
Set oXL = Nothing

Application.ScreenUpdating = True

End Sub

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)
 

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

Top