• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macros for saving sheet

Flow

New Member
hi guys hope all is well.



i want to write a macro so that it saves its name according to Cell C8 ( there will be a name typed in manually) and also saves to a specific folder according to Cell A4 ( Drop down list with client names) i have folders with client names already in my documents. is it possible?



Thanks in advance
 
Hi @Flow, a sample code to get started, adapt the path and the name of the sheet in the code, if you don't want the message to appear you can comment on the relevant line
Code:
Sub SaveActiveSheetByClient()
'https://chandoo.org/forum/threads/macros-for-saving-sheet.57778/

    Dim fileName As String, folderPath As String, fullPath As String
    Dim newWorkbook As Workbook

    fileName = Worksheets("Sheet1").Range("C8").Value '<<==== ADAPT Sheet name if needed
    
    folderPath = "C:\Users\Username\Documents\" & Worksheets("Sheet1").Range("A4").Value '<<==== ADAPT the PATH
    
    ' Check if folder exists
    If Dir(folderPath, vbDirectory) = "" Then
        MsgBox "the folder does not exist.", vbExclamation
        Exit Sub
    End If
    
   fullPath = folderPath & "\" & fileName & ".xlsx"
    
    Application.ScreenUpdating = False
    
   ActiveSheet.Copy
    
    Set newWorkbook = ActiveWorkbook
    
    newWorkbook.SaveAs fullPath
    
    newWorkbook.Close
    
    MsgBox "sheet saved successfully: " & fullPath

End Sub
 
Back
Top