How to call a macro from other workbook?

  • Another way is: Copy your macro to a new blank workbook and save this workbook as a "xla" fie. Then Add-in this file in your excel (Tools > Add-Ins > Browse > then select the file you saved as xla.


    Now you can use your macro any workbooks.

  • Erm, why must be a new workbook? Can I just save my current workbook directly as .xla file? My workbook contain a database and a lot of useforms, marco also.... Is is possible to transfer it to a xla addIns? Just something similar like the frontline system(solver.com) solver addIns. Can someone pls enlight me how i can achieve this?


    Thank



    Quote

    Originally posted by Maqbool
    Another way is: Copy your macro to a new blank workbook and save this workbook as a "xla" fie. Then Add-in this file in your excel (Tools > Add-Ins > Browse > then select the file you saved as xla.


    Now you can use your macro any workbooks.

  • hhfei,


    This assumes that the workbook that contains the Macro you want to run is already open as either a visable workbook or addin.


    Application.Run "'MyFile.xls'!MyMacro"


    If the workbook is not open you will need to have it open - run your macro - have it shut.


    One way this can be done:


    Sub OpenAndRun() 'Untested
    'Filesearch is great for non specific file location
    With Application.FileSearch
    .NewSearch
    .LookIn = "C:\Temp\MyFiles\"
    .SearchSubFolders = True
    .FileName = "MacroFile.xls"
    .MatchAllWordForms = True
    .FileType = msoFileTypeAllFiles
    If .Execute() > 0 Then
    For I = 1 To .FoundFiles.Count
    Workbooks.Open FileName:=Application.FileSearch.FoundFiles(I)
    Application.Run "'MacroFile.xls'!MyMacro"
    Application.Workbooks("MacroFile.xls").Close savechanges:=False
    Next I
    End If
    End With
    End Sub


    Pleace the attached files into your C:\Temp Directory and experriment.


    Regards


    AJW

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!