+ Reply to Thread
Results 1 to 4 of 4

Template with Macro won't work once copy of template is made and file name is changed

  1. #1
    Registered User
    Join Date
    05-15-2013
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Template with Macro won't work once copy of template is made and file name is changed

    I created a Simple Macro to go to another excel file and copy information from that excel file back into a template. However since it is a template the file name will change when a copy is made to be used and because I created my macro by recording it, it won't work in the new file because of the new file name. How do I make this macro dynamic with the changing file name? It errors at the - Windows("Trial Updated_Sharon_DO NOT USE.xlsm").Activate- line because the file name has changed.

    Here is my Macro (I am very new at writing macro's so please forgive my crude programing below):

    Sheets("Master_Part_List").Select
    Range("A1").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.ClearContents
    Range("A1").Select
    Workbooks.Open Filename:="Z:\Jobs\HARTJE MAST.xlsx"
    Range("D1").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.Copy
    Windows("Trial Updated_Sharon_DO NOT USE.xlsm").Activate
    ActiveSheet.Paste
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Bid Material").Select

    Thanks for what ever assitance that can be provided

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Template with Macro won't work once copy of template is made and file name is changed

    Hi, Sharonn,

    maybe use some objects for this (code is unteste):
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    05-15-2013
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Template with Macro won't work once copy of template is made and file name is changed

    Hi Holger

    Thanks for this. I am having two errors with it (Again so new at this that it might just be something easy I am missing):

    1) I am getting a run-time error at - sheets ("Bid Material").Select line. Not sure why.
    2) Also it is getting to this point however the information that was copied from the Hartje Mast file is not pasting. It is suppose to paste into a tab titiled "Mater_Parts_List". Since I used the Macro record button I doesn't look like this was included in my first post.
    3) The Sheets("Bid Material").Select is the last thing that should occur setting the screen view for the user back to that tab.

    Again Thanks for taking the time to help
    Sharon

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Template with Macro won't work once copy of template is made and file name is changed

    Hi, Sharonn,

    regarding Sheets("Bid Material").Select as well as not pasting the code I think this sheet is within the worksheet which holds the code and that I mixed the workbooks. If you skip the code lines like
    Please Login or Register  to view this content.
    it should do fine. As the newly opened workbook will be closed I don´t know if it really is necessary to select the sheet (that sheet would have been the active sheet within the workbook with code).

    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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