+ Reply to Thread
Results 1 to 7 of 7

Calling macro from another workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    03-21-2014
    Location
    Essex, England
    MS-Off Ver
    Excel 2008
    Posts
    16

    Calling macro from another workbook

    Hi,

    I open a .csv file and run a personal macro on it to format the data. It then opens another file, in which I want it to run a macro within the workbook.
    I have the below code, but his keeps giving me the error
    "Run-time error '1004': Cannot run the Macro '!MakeChanges'. The macro may not be available in this workbook or all macros may be disabled."

    I can enter the workbook and manually execute the macro (therefore macros are not disabled), but want it to automatically run, from my personal macro.

    This is my code

    Public Sub MakeChanges()
    
     Dim  toolWB As Workbook
    
     Workbooks.Open Filename:= _
            "C:\Users\me\Desktop\DataTest.xlsm", Password:="abcde"
        
     Set toolWB = ActiveWorkbook
    
    
    toolWB.Application.Run ("!newiTime")

    What is causing the error and how can I fix this? Any help, greatly appreciated!!
    Last edited by alansidman; 08-18-2017 at 06:52 AM.

  2. #2
    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: Calling macro from another workbook

    Hi,

    How are you calling the MakeChanges routine? If you are using Run, you should include the workbook name- in single quotes- before the exclamation mark.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    03-21-2014
    Location
    Essex, England
    MS-Off Ver
    Excel 2008
    Posts
    16

    Re: Calling macro from another workbook

    Hi,

    I have amended it, as per your suggestion and no longer get the pop up error. However, it just closes the workbook that has the macro in it instead and does not run the macro.

    Public Sub MakeChanges()
    
     Dim toolWB As Workbook
    
     Workbooks.Open Filename:= _
     "C:\Users\me\Desktop\DataTest.xlsm", Password:="abcde"
     Set toolWB = ActiveWorkbook
     Application.Run ("'DataTest.xlsm'!newiTime") 
    
    End sub
    Last edited by alansidman; 08-18-2017 at 06:52 AM.

  4. #4
    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: Calling macro from another workbook

    First, please use code tags when posting code, per the forum rules.

    Second, the error you mentioned in your original post, related to running the macro you posted, not the macro in the workbook you are opening- which is why I asked how you were running the posted macro. There is nothing in what you have posted that closes any workbooks so I can't comment further. Perhaps you could post all the relevant code?

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,744

    Re: Calling macro from another workbook

    @garveyarmy
    I have corrected your posting to include code tags. I can see you attempted to do so, but missed the point on placing them on either end of your code. Highlight your code and then click on the # button to ensure that code tagging is enacted.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  6. #6
    Registered User
    Join Date
    03-21-2014
    Location
    Essex, England
    MS-Off Ver
    Excel 2008
    Posts
    16

    Re: Calling macro from another workbook

    Thanks, but think I have just found my error!
    Cheers for the help!!!

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,744

    Re: Calling macro from another workbook

    In an effort to help others who may encounter a similar situation, please explain what you found as your error and how you corrected it. Many people use this forum as a database of information when attempting to seek their own solutions.

+ 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. Manipulating ActiveWorkbook when calling macro from Personal Macro Workbook
    By 146considerations in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-05-2017, 12:16 AM
  2. Error when calling a 'sheet macro' inside a workbook wide macro
    By Rhino_dance in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-09-2016, 03:46 PM
  3. Calling a macro in a protected workbook
    By GJChurchward in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-05-2015, 07:18 AM
  4. calling an event macro from a different workbook
    By cwchan220 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-25-2014, 10:32 AM
  5. Calling Macro on Closing of Workbook
    By Dirigo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-26-2011, 02:57 PM
  6. Calling macro in another workbook
    By scabral in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2009, 02:03 PM
  7. Calling Macro From Different Workbook
    By Launchnet in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-23-2008, 07:03 PM

Tags for this Thread

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