+ Reply to Thread
Results 1 to 6 of 6

Save a worksheet as a new workbook along with VBA codes

  1. #1
    Registered User
    Join Date
    09-04-2023
    Location
    Germany
    MS-Off Ver
    365
    Posts
    28

    Save a worksheet as a new workbook along with VBA codes

    I have a worksheet ( Sheet1) which contains an overview table which counts number of green and red colored cells. ( Clicking OVERVIEW button do this)
    Save Button saves the Sheet1 as a new workbook in the same workfolder. But the newly saved files shows #NAME? in G2 and G3 as the function and vba code is missing in the newly created workbook.

    Is there a way to save the vba codes also to the new workbook ?

    Thanks
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: Save a worksheet as a new workbook along with VBA codes

    is it saving to .xlsm? or .xls?
    using .xlsx will erase the vb code.

    COPY the sheet into new wb will NOT transfer code.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Save a worksheet as a new workbook along with VBA codes


    As a reminder when the original VBA procedure is located within the worksheet module
    that works obviously just with the single Worksheets.Copy codeline !

    Another obvious way as the attachment contains a single worksheet : just use Workbooks.SaveCopyAs rather than Worksheets.Copy …

  4. #4
    Registered User
    Join Date
    09-04-2023
    Location
    Germany
    MS-Off Ver
    365
    Posts
    28

    Re: Save a worksheet as a new workbook along with VBA codes

    Quote Originally Posted by Marc L View Post

    As a reminder when the original VBA procedure is located within the worksheet module
    that works obviously just with the single Worksheets.Copy codeline !

    Another obvious way as the attachment contains a single worksheet : just use Workbooks.SaveCopyAs rather than Worksheets.Copy …
    Hi Marc ,
    The only issue with Workbooks.SaveCopy As is: i have several other worksheets in the workbook ( around 10 worksheets) and i need only specific 3 sheets to be saved a snew workbook. I can defineitly use Delete sheets and then save the workbook as new Workbook. But then i will have to Not save the original Workbook.. a bit triring :P

  5. #5
    Registered User
    Join Date
    09-04-2023
    Location
    Germany
    MS-Off Ver
    365
    Posts
    28

    Re: Save a worksheet as a new workbook along with VBA codes

    Quote Originally Posted by ranman256 View Post
    is it saving to .xlsm? or .xls?
    using .xlsx will erase the vb code.

    COPY the sheet into new wb will NOT transfer code.
    Hi Ranman256
    thanks for the tip

  6. #6
    Registered User
    Join Date
    09-04-2023
    Location
    Germany
    MS-Off Ver
    365
    Posts
    28

    Re: Save a worksheet as a new workbook along with VBA codes

    I found another workaround for my problem. Instead of using a function to count colored cells. i use this formula. This can be then without any issues copied to a new workbook


    Get count of rows where both cell values match -->
    Please Login or Register  to view this content.
    Get count of rows where both cell values differ -->
    Please Login or Register  to view this content.
    Closing this thread and thanks for all inputs

+ 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: 7
    Last Post: 06-22-2018, 12:07 PM
  2. Save a single worksheet from a workbook as a separate read only workbook
    By jmking1999 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2017, 09:49 AM
  3. Save worksheet as workbook but with 'save as' feature
    By jjin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2016, 04:43 PM
  4. [SOLVED] save sheet as macro enabled workbook using codes
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-29-2014, 02:23 PM
  5. Combining Two Codes (from Workbook and Worksheet)
    By FallingDown in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-30-2011, 04:19 AM
  6. Incremental save. Save just one worksheet of a workbook?
    By dylanemcgregor in forum Excel General
    Replies: 2
    Last Post: 09-09-2009, 05:19 PM
  7. Replies: 3
    Last Post: 06-27-2005, 01:05 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