+ Reply to Thread
Results 1 to 16 of 16

Running Public Sub in one workbook to run another macro in another workbook

  1. #1
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Running Public Sub in one workbook to run another macro in another workbook

    I am trying to run a macro in a second workbook by running a public sub macro in the first workbook. I found the following code on the internet, which does not work. I think I am close to solving this, but not close enough. The name of the macro is called "Put_Macros_Together_In_Matter_Names_and_Numbers". And the file path of the SECOND workbook is ("C:\Users\acc\Documents\Macros\Time macro - test.xlsm"). By the way, both workbooks were open when I tried running the macro, but somehow it didn't work. here is the "errant" code:
    Please Login or Register  to view this content.
    Please let me know if you can fix this.

    Best,
    AndrewStupendo

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Running Public Sub in one workbook to run another macro in another workbook

    Have you tried using Application.Run instead of Call?

    By the way, if the other workbook is already open is it open in another instance of Excel?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Running Public Sub in one workbook to run another macro in another workbook

    Yes, I did try that but it did not work. Also I am using the macro in question in combination with other public macros. So I have to use a public macro to do this.

  4. #4
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Running Public Sub in one workbook to run another macro in another workbook

    No both excels are open on the same computer using the same version of excel, if that's what you mean.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Running Public Sub in one workbook to run another macro in another workbook

    Sounds like you do have 2 instances of Excel to me.

    What happens if you try using oWb.Application.Run?

    That might work as oWb.Application should refer to the instance of Excel that the workbook oWb is open in.

  6. #6
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Running Public Sub in one workbook to run another macro in another workbook

    I tried the following code, which did not work either:
    Please Login or Register  to view this content.
    Can someone please help?

    Thanks.

  7. #7
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Running Public Sub in one workbook to run another macro in another workbook

    Also tried this, which did not work either:
    Please Login or Register  to view this content.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Running Public Sub in one workbook to run another macro in another workbook

    Hi,

    In which module in the workbook is the Put_Macros_Together_In_Names_and_Numbers code located?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Running Public Sub in one workbook to run another macro in another workbook

    Did you try what I suggested?
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Running Public Sub in one workbook to run another macro in another workbook

    The module for the macro "Put_Macros_Together_In_Names_and_Numbers" is located the module in "Sheet 2" with the name "Matters Names & Numbers". Also the name of the workbook is 'Individual Time macro - final version.xlsm'.

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Running Public Sub in one workbook to run another macro in another workbook

    Then you must use

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Running Public Sub in one workbook to run another macro in another workbook

    Hello All,
    I tried the following two macros, neither of which worked for different reasons.
    The first macro did not work because the file path is not correct. I tried different paths for the file (I even put the file on my desktop) and the compiler would not accept the file path coding. here is the first macro with the problem coding in red:
    Please Login or Register  to view this content.
    I found another macro which does the same thing. The file path seemed OK, but when it came to use the "Application.Run" line of coding, the compiler would not accept it. here is the coding of the second macro with the problem line in red.
    Please Login or Register  to view this content.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Running Public Sub in one workbook to run another macro in another workbook

    Any chance you could upload sample workbook(s)?

    Click on GO ADVANCED, scroll down and click Manage Attachments.

  14. #14
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Running Public Sub in one workbook to run another macro in another workbook

    OK. I will edit the workbooks and I will get back to you.

  15. #15
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Running Public Sub in one workbook to run another macro in another workbook

    GetObject requires a full path including the file name. Thus the first code needs to read
    Please Login or Register  to view this content.
    The second code is missing some concatenation
    Please Login or Register  to view this content.
    I might also suggest that your code belongs in a regular module rather than a worksheet code module.

  16. #16
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Running Public Sub in one workbook to run another macro in another workbook

    This is not working because it is just not possible to find the correct file path for the second workbook, given the network setup that I have. I am therefore closing this thread as unsolved. No one's fault except the network's.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Running A Macro With Information From the Workbook On Opening The Workbook
    By Jaynestown in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-17-2013, 03:04 PM
  2. Replies: 2
    Last Post: 06-21-2013, 08:59 PM
  3. [SOLVED] copy all sheets from one workbook to the workbook running the macro
    By synergio in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-28-2012, 06:20 AM
  4. Running a Macro in a different workbook
    By fredblogs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-19-2011, 11:36 AM
  5. Running workbook macro from personal workbook
    By mashley in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2009, 08:44 AM
  6. Running macro from different workbook
    By koklok in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-22-2008, 04:55 PM
  7. Running a macro in another workbook
    By Phil_V in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2008, 05:30 AM
  8. Replies: 9
    Last Post: 07-25-2005, 08:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1