So I have a sheet named "Travel Orders" and I am trying to make it run against a version checker, but I am having issues with it. My code is as follows:
I get the following error:
Not sure how to fix. And in the "error" part of the code I only really need an error msg box if something goes wrong. Any help would be much appreciated.
VBA Code:
Option Explicit
Private Sub Workbook_Open()
Dim WS As Worksheet
For Each WS In ThisWorkbook.Sheets
WS.Protect Password:="password", UserInterfaceOnly:=True
Next WS
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim WS As Worksheet
Set WS = ActiveSheet
If WS.Name = "Data" Then Exit Sub
If Not Intersect(Target, Range("B5:M14")) Is Nothing Then
Application.EnableEvents = False
Sheets("Travel Orders").Unprotect Password:="password"
WS.Range("M2") = Environ("Username")
WS.Range("M3") = Now
Sheets("Travel Orders").Protect Password:="password"
Application.EnableEvents = True
End If
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim WS As Worksheet
Set WS = ActiveSheet
If WS.Name = "Travel Orders" Then Exit Sub
Sheets("Data").Unprotect Password:="password"
WS.Range("E10") = Environ("Username")
WS.Range("E11") = Now
Sheets("Data").Protect Password:="password"
End Sub
Private Sub Workbook_Open()
Sheets("Travel Orders").Activate
On Error GoTo Error
With Application
.EnableEvents = False
.ScreenUpdating = False
.StatusBar = "Checking Travel Orders Version. Please wait..."
End With
Workbooks.Open "Path To Version Checker.xlsm", , True
Workbooks("Travel Orders.xlsm").Activate
If Workbooks("Travel Orders.xlsm").Sheets("Travel Orders").Range("M1").Value <> Workbooks("Version Checker.xlsm").Sheets("Version").Range("C3").Value Then
Application.StatusBar = "You are running an old version of 'Travel Orders'. Please download the newest version from iShare."
MsgBox "You are running an old version of 'Travel Orders'. Please download the newest version from iShare.", 16, "Wrong Version"
Workbooks("Version Checker.xlsm").Close SaveChanges:=False
With Application
.EnableEvents = True
.StatusBar = ""
End With
Workbooks("Travel Orders.xlsm").Close SaveChanges:=False
End If
Workbooks("Version Checker.xlsx").Close SaveChanges:=False
Cleanup:
Range("B4").Select
With Application
.EnableEvents = True
.StatusBar = ""
End With
Exit Sub
Error:
MsgBox "Error #" & Err.Number & " has occurred." & vbNewLine & vbNewLine & Err.Description & vbNewLine & vbNewLine & "Please contact PERSON for assitance!", 16, "Error Occurred"
Application.DisplayAlerts = False
Application.DisplayAlerts = True
Sheets("Travel Orders").Activate
GoTo Cleanup
End Sub
I get the following error:
Not sure how to fix. And in the "error" part of the code I only really need an error msg box if something goes wrong. Any help would be much appreciated.