Hello,
The code under the workbook is not close to the code I provided. This is what was there
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False
ThisWorkbook.SaveAs "D:\picking logs\" & Sheets("Picking Log with colons").Range("D1").Value & ".xls"
Application.ScreenUpdating = True
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.ScreenUpdating = False
ThisWorkbook.SaveAs "D:\picking logs\" & Sheets("Picking Log with colons").Range("D1").Value & ".xls"
Application.ScreenUpdating = True
End Sub
The code was supposed to be the codes from Post #2 and Post #7 I fixed it for you and also modified it to fit your needs ( change the saving location) I also fixed the extension to save it as an ".xls" I added another layer of security in case the folder does not exists
This is the final under Sheet1 Module:
Private Sub WorkSheet_Change(ByVal Target As Range)
Dim txtLocation As String
Dim txtExtension As String
Dim txtFileName As String
Dim response As Integer
Set Target = Range("D1")
txtLocation = "D:\picking logs\" 'Change this to the location for the files always with a \ at end
txtExtension = ".xls" 'The extention for the file
txtFileName = txtLocation & "Batch " & Target & txtExtension
'lets check of the file exists
If ThisWorkbook.FullName = txtFileName Then
'if the above is true then save the workbook
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True
Else
On Error GoTo Err1
ThisWorkbook.SaveAs Filename:=txtFileName
End If
Exit Sub
Err1:
MsgBox "An error has occurred. Make sure the directory in the macro is valid." & _
vbNewLine & "Nothing was saved", vbCritical + vbOKOnly, "Error Saving File"
End Sub
Here is the final file
Attachment 263835
Thanks
Bookmarks