Results 1 to 10 of 10

Thread: Fire macros from a single macro....

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Fire macros from a single macro....

    Hey guys ,
    i have 4 macros that copy paste data from another workbook.
    I want to have one macro that fires the other 3. Note that each macro is placed into a different sheet, in the same workbook. Is this possible?
    How can we call the other 3 macros if they are in a different sheet?


    Thanks

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Fire macros from a single macro....

    the macros need to be public procedure, at least not private
    vb Code:
    1. sheet1.mymacro
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Re: Fire macros from a single macro....

    Quote Originally Posted by westconn1 View Post
    the macros need to be public procedure, at least not private
    vb Code:
    1. sheet1.mymacro
    what if the macros aree in different workbooks in the same folder.
    can't we do it?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Fire macros from a single macro....

    yes you can do
    vb Code:
    1. Set s = Workbooks("book1.xls").Sheets("sheet1")
    2. Application.Run s.mymacro
    3. ' or for macros in a module
    4. application.run "book1.xls!mymacro"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Re: Fire macros from a single macro....

    Quote Originally Posted by westconn1 View Post
    yes you can do
    vb Code:
    1. Set s = Workbooks("book1.xls").Sheets("sheet1")
    2. Application.Run s.mymacro
    3. ' or for macros in a module
    4. application.run "book1.xls!mymacro"
    i tried to put the code to my main workbook to fire the other macros my i get an error.
    Subscript out of range..
    Set s = Workbooks("All brand Projects.xls").Sheets("sheet1")
    Application.Run s.mymacro
    ' or for macros in a module
    application.run "All brand Projects.xls!mymacro"

    don't we need to open the other workbooks before we fire the macros?
    i placed that code to a module on my main spreadsheet(master data). and i need to link it with the other workbooks so i can run the macros...
    i tried it but am getting errors

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Fire macros from a single macro....

    i did assume they would be open already
    vb Code:
    1. Set s = Workbooks.Open("book1.xls").Sheets("mysheet")
    2. Application.Run s.mymacro
    if you want a workbook object set that first on open, then set the sheet
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Re: Fire macros from a single macro....

    Quote Originally Posted by westconn1 View Post
    i did assume they would be open already
    vb Code:
    1. Set s = Workbooks.Open("book1.xls").Sheets("mysheet")
    2. Application.Run s.mymacro
    if you want a workbook object set that first on open, then set the sheet
    Set s = Workbooks.Open("\\NASFILE02\prou\My O Files\Desktop\status 2\FINA\fiNAL\Publish on\Express.xls").Sheets(" Express Report")
    Application.Run s.Sample4thats my macro.
    am getting this error.
    object doesn't support this property or method.
    any idea on what am doing wrong?

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Fire macros from a single macro....

    can't see from here, the code should work ok, i have tested on a couple of workbooks, you sure the macro name is correct and on the correct sheet
    which line do you get error?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Re: Fire macros from a single macro....

    QUOTE=westconn1;3765403]can't see from here, the code should work ok, i have tested on a couple of workbooks, you sure the macro name is correct and on the correct sheet
    which line do you get error?[/QUOTE]

    am getting error in this line................
    Application.Run s.Sample4

    after s. i just put the name of my macro that is included in a module.....
    is there any way we can run a macro without opening the workbooks?
    updating the workbooks without opening them?

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Fire macros from a single macro....

    is there any way we can run a macro without opening the workbooks?
    updating the workbooks without opening them?
    no, you have to open each make changes and close & save, no need to be visible to the user
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width