Consulting

Results 1 to 2 of 2

Thread: How can I modify this code to use a cell value when naming the new workbooks?

  1. #1

    How can I modify this code to use a cell value when naming the new workbooks?

    Sub SaveShtsAsBook()
    Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&
    MyFilePath$ = ActiveWorkbook.Path & "" & _
    Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4)
    With Application
    .ScreenUpdating = False
    .DisplayAlerts = False
    ' End With
    On Error Resume Next '<< a folder exists
    MkDir MyFilePath '<< create a folder
    For N = 1 To Sheets.Count
    Sheets(N).Activate
    SheetName = ActiveSheet.Name
    Cells.Copy
    Workbooks.Add (xlWBATWorksheet)
    With ActiveWorkbook
    With .ActiveSheet
    .Paste
    .Name = SheetName
    [A1].Select
    End With
    'save book in this folder
    .SaveAs Filename:=MyFilePath _
    & "" & SheetName & ".xls"
    .Close SaveChanges:=True
    End With
    .CutCopyMode = False
    Next
    End With
    Sheet1.Activate
    End Sub


  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi cmetzbower
      'save book in this folder
      .SaveAs Filename:=MyFilePath & "\" & Cells(?,?).Value & ".xls" 'Enter the cell what you want here
      .Close SaveChanges:=True 
    End With

Posting Permissions

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