+ Reply to Thread
Results 1 to 12 of 12

VBA Code to save copy worksheet not entire workbook

  1. #1
    Registered User
    Join Date
    01-09-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    10

    VBA Code to save copy worksheet not entire workbook

    Hi,

    I am using the below code to autosave a copy of a spreadsheet when clicking a button on the worksheet.

    I actually only want to save a copy of the worksheet displayed and not all the sheets from the workbook as this is quite a large spreadsheet. Can anyone offer an amended the code for me so I can make the amendments to the save function I require please.

    Cheers,
    Nick

  2. #2
    Registered User
    Join Date
    01-09-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA Code to save copy worksheet not entire workbook

    Doh!, here's the code I'm currently using:


    Public Sub CommandButton1_Click()
    Dim nom As String
    nom = Day(Date) & "-" & Month(Date) & "-" & Year(Date) & "_" & ActiveWorkbook.Name
    ActiveWorkbook.SaveCopyAs ActiveWorkbook.Path & "\" & nom
    rep = MsgBox("You database has been saved : " & Name, vbYes + vbInformation, "Copy of spreadsheet")
    End Sub

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Code to save copy worksheet not entire workbook

    Maybe:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-09-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA Code to save copy worksheet not entire workbook

    Thanks for the reply John.

    Your code creates the copy of the individual worksheet but fails to save it. I'm getting the following error messages:

    Firstly an error msg in Excel saying it cannot save the file type, need to select a macro enabled file type.

    Following this, whether you select Yes or No, I get another error msg come up in the VBA page with a big red cross with 400 written next to it.

    I am able to manually intervene and save the copy of the spreadsheet but its not very slick with all the error messages and still needs manual saving.

    Any suggestions on how to remedy this?

    Cheers,
    Nick

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Code to save copy worksheet not entire workbook

    Hi Nick:

    Can you attach a sample file which errors?

    Try:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-09-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA Code to save copy worksheet not entire workbook

    Here's the workbook.
    It'll open on the worksheet I am trying to save the copy of. Essentially it is for a user to record data on a daily basis and then have a copy of that data with a record of the date on which the record was taken, ideally in the same folder as the original workbook.

    The sheet the workbook opens on has the code you gave me assigned to the button called 'Autosave a Copy'

    Cheers,
    NickDraft EMS.xlsm

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Code to save copy worksheet not entire workbook

    Try:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-09-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA Code to save copy worksheet not entire workbook

    That's got round the initial msg which comes up regarding saving as a macro enabled workbook, but I still get the 400 error msg in VBA and the copy sheet does not save anywhere.

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Code to save copy worksheet not entire workbook

    I can't duplicate the error you are getting. On the sample provided, I tested it and it did not error?

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Code to save copy worksheet not entire workbook

    Try to error trap it and see what the error says?

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    01-09-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA Code to save copy worksheet not entire workbook

    Could you attach the sample and email back to me please?

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Code to save copy worksheet not entire workbook

    Quote Originally Posted by njohnn View Post
    Could you attach the sample and email back to me please?
    Go to Post #6 to retrieve. I deleted the copy I tested on.

+ 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. Code runs on entire workbook...need it to only run on one worksheet
    By jrobertson2403 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-28-2013, 04:50 PM
  2. Replies: 7
    Last Post: 02-15-2013, 05:31 AM
  3. Save entire workbook as copy in specific folder with VBA
    By cychua in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-01-2012, 08:35 AM
  4. copy entire worksheet to current workbook
    By AJHWilliams in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-16-2011, 08:47 PM
  5. Copy entire workbook then prompt 'save as'
    By sgeorge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-29-2007, 12:10 PM

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