Consulting

Results 1 to 4 of 4

Thread: Running macro on another workbook

  1. #1

    Running macro on another workbook

    I wrote a macro which deletes blank rows and saves the file into a csv file. The name of the xls file which has macro is MacroFile.xls. I want to run this macro on an excel file (Sourcefile.xls). So when I open the macrofile.xls, the macro should run on Sourcefile.xls. I tried using Application.Run("SourceFile.XLS!MyMacroName") in Macrofile.xls. I get error. Any help would be appreciated. Here is what i have in sourcefile.xls.

    sub promacro()
    ' code here
    end sub

    Sub runmacro()


    Application.Run ("C:\folder\Macrofile.XLS!promacro")


    End Sub

    Can someone suggest what am i missing?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You don't need brackets, just

    Application.Run "C:\folder\Macrofile.XLS!promacro"
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    tried, but doesnt work

    thank you. tried, but it doesnt work either. i get the following error

    run-time error '1--4': application-defined or object-defined error.


    Quote Originally Posted by xld View Post
    You don't need brackets, just

    Application.Run "C:\folder\Macrofile.XLS!promacro"

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Couple of points I should have noticed earlier.

    You cannot have macros in a .xlsx file, it must be .xlsm or .xlsb.

    You cannot run a macro from a folder, you have to open it and then run it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •