+ Reply to Thread
Results 1 to 8 of 8

Can't run macros in file unless file it was "saved as" from is in same folder/directory

  1. #1
    Registered User
    Join Date
    02-15-2021
    Location
    East Lansing, MI, USA
    MS-Off Ver
    Office 365 for Mac
    Posts
    4

    Can't run macros in file unless file it was "saved as" from is in same folder/directory

    I created a spreadsheet in Office 365 Excel for Mac that contains macros. They ran fine. I then created several different files from that, saving them under new names, in order to incorporate examples of analysis of different data sets. I then found that I couldn't run the macros in the "saved as" files unless the original file that they were saved from was located in the same folder/directory. This was true even though when I view the macros "in the current workbook" they are listed.

    Is there some way to "break the link" between new files and the original file and let the macros in the new files run without referring to the original file in the same folder/directory? Thanks!

    --Eric55

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Can't run macros in file unless file it was "saved as" from is in same folder/director

    You should able to save a macro file anywhere, and have it still run, unless the code refers explicitly to some particular folder, or if there are other files it is expecting to find in its own folder that are not there. This is very hard to diagnose with the limited information here. Can you show your macro code, or attach the file? If you paste code, use code tags in your post. See yellow banner at the top of the page for attaching a file.

  3. #3
    Registered User
    Join Date
    02-15-2021
    Location
    East Lansing, MI, USA
    MS-Off Ver
    Office 365 for Mac
    Posts
    4

    Re: Can't run macros in file unless file it was "saved as" from is in same folder/director

    Thanks; I think I see the problem, but not sure how best to resolve it. The macro (listed below) specifically refers to the file in which I first created it. I guess when I save the file under a new name, the macro's reference to that file is unchanged (?). The macro is:

    Sub MRR()
    '
    ' MRR Macro
    ' Combines all macros
    '
    ' Keyboard Shortcut: Ctrl+j
    '
    Application.Run "Economic_Analysis.GRAIN_Agronomic_Trials.50Treatments.xlsm!Copy1"
    Application.Run "Economic_Analysis.GRAIN_Agronomic_Trials.50Treatments.xlsm!Sort1"
    Application.Run "Economic_Analysis.GRAIN_Agronomic_Trials.50Treatments.xlsm!Copy2"
    Application.Run "Economic_Analysis.GRAIN_Agronomic_Trials.50Treatments.xlsm!Sort2"
    Application.Run "Economic_Analysis.GRAIN_Agronomic_Trials.50Treatments.xlsm!Filter1"
    End Sub

    I have a number of files--created to illustrate analysis of different datasets--that use this macro. Do I need to edit the file names in each of these files to correspond their modified filenames?

    Thanks!

    Eric55

  4. #4
    Registered User
    Join Date
    02-15-2021
    Location
    East Lansing, MI, USA
    MS-Off Ver
    Office 365 for Mac
    Posts
    4

    Re: Can't run macros in file unless file it was "saved as" from is in same folder/director

    Hmm . . . I guess a simpler solution might be just to eliminate the filenames so that the lines read:
    Application.Run "Copy1", etc. (?) Should have thought of that.

    Eric55

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Can't run macros in file unless file it was "saved as" from is in same folder/director

    Code tags are required by our rules.

    There are two ways to add code tags. One is to select the code part of the text so it is highlighted, then press the "#" button in the edit controls. The other is to simply type in the tags:

    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code]


    Why use code tags? Code tags:

    1. Are required by rules (see rule #2)
    2. Preserve spacing used to show code structure (otherwise leading spaces and repeated spaces are removed)
    3. Add scroll bars to navigate code with long lines or a lot of lines

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Can't run macros in file unless file it was "saved as" from is in same folder/director

    If these macros are in the same file as the code you are showing you just need:

    Please Login or Register  to view this content.
    There is no reason to use Application.Run to call internal Subs.
    Last edited by 6StringJazzer; 02-18-2021 at 12:13 PM.

  7. #7
    Registered User
    Join Date
    02-15-2021
    Location
    East Lansing, MI, USA
    MS-Off Ver
    Office 365 for Mac
    Posts
    4

    Re: Can't run macros in file unless file it was "saved as" from is in same folder/director

    TO 6StringJazzer: Many thanks! I will follow your suggestions. Not sure why the Application.Run got inserted originally.
    Also, thanks for clarifying the "code tags" rule. I saw that when I joined the forum but didn't know what it meant.

    Eric55

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Can't run macros in file unless file it was "saved as" from is in same folder/director

    You might have noticed that I messed up my closing code tag, which I just fixed.

+ 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. Replies: 2
    Last Post: 11-15-2018, 06:03 PM
  2. Replies: 1
    Last Post: 10-24-2014, 12:32 AM
  3. [SOLVED] Script to save to folder in "v:\dept2", confirm file saved, then delete from "v:\dept1"
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2014, 11:42 AM
  4. [SOLVED] How to select any file in folder name (Left = "Final Test") then kill the file
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-30-2013, 12:40 AM
  5. MSoffice Outlook 2003 message to be saved in C dir with the file name "From" "Sent" "Sub"
    By shailendra0509 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2012, 01:32 AM
  6. Transfert cell values from file "A" to file "B" skipping columns in file "B".
    By Sentrosi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2009, 11:11 PM
  7. Replies: 3
    Last Post: 11-02-2005, 06:17 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