+ Reply to Thread
Results 1 to 4 of 4

Save worksheet as new workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    09-20-2015
    Location
    Haarlem, The Netherlands
    MS-Off Ver
    Office 2016
    Posts
    16

    Question Save worksheet as new workbook

    Hi all,

    I want to make a macro that allows me to easily save worksheets as new workbooks in the same path as the original workbook.

    This is what I got so far:

    Sub SaveWorksheet()
      Dim wb As Workbook
      Dim Start As String
      Dim Finish As String
      Dim Name As String
     
      Start = Sheets("Example").Range("F5")
      Finish = Sheets("Example").Range("M5")
      
      Sheets("Example").Copy
      Set wb = ActiveWorkbook
      Name = "Text" & " " & Start & "" & " - " & "" & Finish
      With wb
        .SaveAs ThisWorkbook.Path & "\Name.xlsx"
        wb.Close
      End With
    End Sub
    In this code 'Start' and 'Finish' are dates in cells.

    The only problem is that the worksheet isn't saved with the name I gave it behind 'Name' but actualy with the name Name.xlsx..

    Is there any easy way that can fix my problem?

    Hope you have some tips

    - Daan
    Last edited by Bossie94; 09-21-2015 at 10:05 PM.

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Save worksheet as new workbook

    It's being saved as name.xlsx because you are passing a literal string.
    Anytime you have "anything with quotes" that is what you are passing.

    If you have a string variable named "name", then you pass it without quotes, since it's a string you pass it into another string with & name &

    SaveAs ThisWorkbook.Path & "\" & Name & ".xlsx"
    Last edited by skywriter; 09-21-2015 at 10:20 PM.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Registered User
    Join Date
    09-20-2015
    Location
    Haarlem, The Netherlands
    MS-Off Ver
    Office 2016
    Posts
    16

    Re: Save worksheet as new workbook

    You are my hero!

    Thanks for the quick response, it works perfect now.

    Cheers
    - Daan

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Save worksheet as new workbook

    Thanks for the rep. points.

    Another very useful tool when you are trying to build a string is the immediate window. Control + G is the shortcut.

    You can build your name string and then in the line after it is built, you enter Debug.Print Name and it will printout in the immediate window and you can check it for errors.

    Please click the Thread Tools drop down box above your first post and choose solved.

+ 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] Export/Save a worksheet in a workbook without changing the name of the workbook?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2013, 06:04 PM
  2. Save Worksheet as Workbook
    By hecgroups in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-08-2013, 08:15 AM
  3. [SOLVED] Save Every Worksheet in a Workbook to individual PDF files that use the worksheet name
    By schmidt62 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-24-2012, 12:00 AM
  4. [SOLVED] Copy certain cells before save from a worksheet in one workbook to a worksheet in another
    By Marianne Rachmann in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2012, 07:16 PM
  5. Save Worksheet to another Workbook.
    By Baziwan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-20-2010, 06:21 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. Save worksheet vs workbook
    By JWM6 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-03-2006, 11:45 AM
  8. Replies: 3
    Last Post: 06-27-2005, 01:05 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