Hello. I use the following code to save a specific sheet in a folder in the same path as the main workbook. It works fine for me. But I'm looking for some modifications
1) It is saved in Partition C in a specific folder, let it be “test”, if it does not exist, it is created and the workbook is saved inside it.
2) In some cases, the file names are identical. If the same name is found, a sequence must be added to the new file while keeping the oldest one without deleting it.
1) It is saved in Partition C in a specific folder, let it be “test”, if it does not exist, it is created and the workbook is saved inside it.
2) In some cases, the file names are identical. If the same name is found, a sequence must be added to the new file while keeping the oldest one without deleting it.
VBA Code:
Sub Save_folder_Excel2()
Dim WS As Worksheet: Set WS = Sheet1
Dim path As String, folderName As String, Fname As String, Client As String
Dim shape As Excel.shape, rng As Range
Client = [D3].Value
path = ThisWorkbook.path & "\"
On Error Resume Next
If Len([D3].Value) = 0 Then: Exit Sub
With Application
.ScreenUpdating = False
.DisplayAlerts = False
folderName = "Client STG"
MkDir path & folderName
Fname = folderName & "\" & Client
WS.Copy
Set rng = [B1:F22]
With rng
.Value = .Value
.Validation.Delete
End With
For Each shape In ActiveSheet.Shapes
shape.Delete
Next
Application.ActiveWorkbook.SaveAs Filename:=path & Fname & ".xlsx", FileFormat:=51
ActiveWorkbook.Close
.DisplayAlerts = True
.ScreenUpdating = True
End With
On Error GoTo 0
MsgBox "done" & vbLf & vbLf & path & _
"", vbInformation, folderName
End Sub