+ Reply to Thread
Results 1 to 3 of 3

Macro in Template opens new workbook or macro file not found error

  1. #1
    Registered User
    Join Date
    05-24-2017
    Location
    Seattle, Wa
    MS-Off Ver
    2016
    Posts
    2

    Macro in Template opens new workbook or macro file not found error

    I am using excel from office 365/2016. I recorded a macro in a template. Template is called from another application(MSPROJECT) and when opening, it opens as an excel workbook with a new name. When the macro is run from the new workbook, it opens the original template and modifies that template rather than the new workbook. If I update and rename the template and delete the old template, the macro does not work at all and says it cannot find the old template. How do I get the macro to be part of the workbook from which it is run rather than referencing the template where it was created? Note that the templates are shared with different people after updating rather than having a central location, so I am trying not to have the macros associated with files on my machine.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,956

    Re: Macro in Template opens new workbook or macro file not found error

    Without seeing the files, I can only speculate what is going on. The Second Commandment of VBA is "Thou shalt always tell Excel where you want it to be." (The First Commandment is "Option Explicit - thou shalt always declare variables.") Your idea of what is active and Excel's idea of what is active might be two different things.

    Unless you are certain that a workbook is active, like when you just opened it or created it, it's best to set a pointer to it.
    Please Login or Register  to view this content.
    And the same holds true for sheets
    Please Login or Register  to view this content.
    Now shS is its own entity. It knows that it belongs to workbook xlS so you can use it as shS without having to reference its parent workbook. You can address ranges in it (shS.Range("A1:Q13"), copy from it or paste to it.

    The other possible area of error would be using FileSaveAs. Instead use FileCopy and work with the copy. There will be no confusion as to which file is original and which one is the working copy.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    05-24-2017
    Location
    Seattle, Wa
    MS-Off Ver
    2016
    Posts
    2

    Re: Macro in Template opens new workbook or macro file not found error

    Thanks for the reply DFLAK. Good information and it helped me troubleshoot the real problem. It was not the macro code. It is the fact that I added the macro to the Ribbon and Quick access toolbar. If I use the macro call from the ribbon, it opens the original workbook and runs the macro from the original file. If I just run the macro from the developer tabs it works fine from the open workbook. So the new question is whether you can set the macro call from the Ribbon and quick access toolbars to where it just looks at the current workbook.

+ 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. Error with macro which creates new workbook and pastes a template in
    By cheethamz17 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-23-2016, 03:07 AM
  2. [SOLVED] How to automatically run a macro when template opens, but not when the copy is opened.
    By shoes1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2015, 01:24 PM
  3. [SOLVED] Whenever I open an Excel file, it also opens my "PERSONAL" macro workbook
    By MetroBOS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-04-2014, 03:24 PM
  4. Macro which opens workbook, runs macro, copies and then closes
    By Vihral in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-06-2013, 11:45 AM
  5. [SOLVED] New Template Workbook Set Up, find file directory, user input for use in macro
    By RichTea88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2013, 04:50 AM
  6. Replies: 7
    Last Post: 07-25-2011, 10:00 AM
  7. I Visual Basic Error "File Not Found" when Excel opens
    By Brent E in forum Excel General
    Replies: 1
    Last Post: 03-02-2005, 12:06 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