![]()
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." & _ ActiveSheet.Protect "hi" End Sub
I keep getting a syntax erro for this code please help.
Bookmarks