Consulting

Results 1 to 7 of 7

Thread: Save Sheet As New Work Book

  1. #1

    Save Sheet As New Work Book

    Hi Guys,
    I have found the below code to save sheet as new workbook but what I wanted to know if it is possible to change the save name
    each time the macro is run to the values on sheet 1 in cells B2 & B3

     
    Sub sb_Copy_Save_Worksheet_As_Workbook()
    Dim wb As Workbook
    Set wb = Workbooks.Add
    ThisWorkbook.Sheets("Sheet2").Copy Before:=wb.Sheets(1)
    wb.SaveAs "C:\temp\test1.xlsx"
    End Sub

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    Sub sb_Copy_Save_Worksheet_As_Workbook()
        Dim myPath As String
        Dim myFileName As String
        
        myPath = ThisWorkbook.Sheets("Sheet1").Range("b2").Value
        myFileName = ThisWorkbook.Sheets("Sheet1").Range("b3").Value
    
        ThisWorkbook.Sheets("Sheet2").Copy
        ActiveWorkbook.SaveAs myPath & myFileName 
        
    End Sub

  3. #3
    Can i ask how you set the save location?

  4. #4
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    I guess.

    cell B2: C:\temp\
    cell B3: test.xlsx



  5. #5
    My appologies I explained that really badly. Ideally if possible could the Filename be the values in B2 & B3 and the File location would be P:\customer service back order info

  6. #6
    I have tried amending it myself but for some reason the file just isnt saving in the requested location

  7. #7
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    you should modify these lines

    > myPath = ThisWorkbook.Sheets("Sheet1").Range("b2").Value
    > myFileName = ThisWorkbook.Sheets("Sheet1").Range("b3").Value

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •