+ Reply to Thread
Results 1 to 7 of 7

Copy/Save As xlsm workbook to new xlsm workbook is not copying the code with it

  1. #1
    Registered User
    Join Date
    07-31-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Talking Copy/Save As xlsm workbook to new xlsm workbook is not copying the code with it

    I have a file in which the customer will fill out a request for a new order. I want them to open the file and automatically, once macros are enabled, it will make a copy of itself to a new file and close the original. They'll make their changes in the new file and hit the submit changes and notify button in which the file will be saved, closed and emailed. Currently the email attaches a copy of the file but I will be changing that to a link to the file. These files are stored on a network share. It makes the copy and saves it as an xlsm but the code does not copy with it, therefore, the submit changes and notify will not function. Neither will the calendars. I've attached a copy of the document, removed all sensitive data and redirected it to a local folder verses the network folder for the purpose of getting help in this forum. I've searched for some solutions but haven't been able to get it to work. I'm nowhere near an expert on this so any help you can provide would be appreciated.

    SOLVED: Added "Purchase Request.xlsm" with the code fixed. Thanks so much for the help!
    Attached Files Attached Files
    Last edited by Grinchy; 08-02-2013 at 10:56 AM. Reason: Solved - Attaching new doc with fixed code

  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,721

    Re: Copy/Save As xlsm workbook to new xlsm workbook is not copying the code with it

    The file you have attached has no code so can't be diagnosed. The button attempts to call code in another file

    'Purchase Request_Forum Help.xlsm'!CDO_Mail_Workbook

    and so, of course, fails.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    07-31-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Copy/Save As xlsm workbook to new xlsm workbook is not copying the code with it

    I'm not sure why you couldn't see the code but here it is:

    ThisWorkbook:
    Please Login or Register  to view this content.
    Last edited by Grinchy; 08-01-2013 at 01:19 PM. Reason: Forgot to wrap the code

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

    Re: Copy/Save As xlsm workbook to new xlsm workbook is not copying the code with it

    Your code is much more complicated than what is necessary. It is unnecessary to create a new workbook and then copy content. You just need to save the existing workbook with a new name, and it continues to be the active workbook. I have tested this.

    Please Login or Register  to view this content.
    However, I am still concerned about your overall approach. You said that you want the macros to stay intact. As a consequence, the next time it's opened it's going to make another 2nd generation copy of itself. For example, when the user opens "Purchase Request.xlsm" it is saved as "2013-08-01 20-25-00 Purchase Request.xlsm". If someone opens that second file it's going to be saved as "2013-08-01 21-34-00 2013-08-01 20-25-00 Purchase Request.xlsm". Therefore nobody can ever edit the original file!

    I think you still have a problem with your Submit Changes button, because it refers to a macro in the original file. I think you may want to use an ActiveX control that will call a macro in the file that contains it. Here is your file >Purchase Request.xlsm< with my updated code plus an alternative for your button.

    By the way here is what I see >Grinchy_nocode.jpg< when I try to look for code in the file you attached.

  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,721

    Re: Copy/Save As xlsm workbook to new xlsm workbook is not copying the code with it

    I just realized why I don't see your code. When I open your file, I enable macros and of course, it makes a copy of itself. Without the code. Which was your original problem. My bad.

  6. #6
    Registered User
    Join Date
    07-31-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Copy/Save As xlsm workbook to new xlsm workbook is not copying the code with it

    I think everything is working the way I want with the exception that you pointed out about the 2nd generation copy. Is there a way to say in the code you provided, that "If" the file is titled "Purchase Request.xlsm" then perform this action?

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

    Re: Copy/Save As xlsm workbook to new xlsm workbook is not copying the code with it

    Yes, you would update the code in ThisWorkbook to look like this:

    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 08-02-2013 at 09:30 AM. Reason: add code tags

+ 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. [SOLVED] Copy and Paste data from .xlsm workbook to .xls workbook
    By pinstripe05 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-04-2013, 11:54 AM
  2. Replies: 3
    Last Post: 05-21-2013, 08:22 AM
  3. Save file xls file as xlsm - macro won't run in xlsm workbook
    By captbluefin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-07-2012, 11:39 AM
  4. VBA to save a copy of .xlsm workbook as .xlsx
    By lanziniad in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2012, 02:00 AM
  5. Save as .xlsx and not as .xlsm with VBA code
    By Blue_Wings in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-22-2010, 04:37 AM

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