Run-time error '1004' when executing Exit Sub command line:
The following code is run from a master workbook. It opens 4 other workbooks and exit. It does what it is supposed to do, but when it gets to the “Exit Sub” command line, it gives an error message of “Run-time error ‘1004’:
Activate method of Range class failed.” 4 times. 
Could you please assist in solving this error?
Best regards,
Henk Stander
Sub OpenContractorScoreCardWorkbooks()
Dim PathFabrication As String
Dim FileNameFabrication As String
Dim PathMachineAndValveShop As String
Dim FileNameMachineAndValveShop As String
Dim PathRiggersAndCranes As String
Dim FileNameRiggersAndCranes As String
Dim PathServices As String
Dim FileNameServices As String
Dim MasterFile As String
Dim wb As Workbook, strName As String, strPath As String
' Run the Error handler "ErrHandler" when an error occurs.
On Error GoTo Errhandler
MasterFile = ThisWorkbook.Name
Application.ScreenUpdating = True
Range("A1").Activate
Range("P3") = "BUSY OPENING WORKBOOKS - PLEASE WAIT!"
Application.ScreenUpdating = False
PathFabrication = Range("I5").Value
FileNameFabrication = Range("B5").Value
PathMachineAndValveShop = Range("I12").Value
FileNameMachineAndValveShop = Range("B12").Value
PathRiggersAndCranes = Range("I19").Value
FileNameRiggersAndCranes = Range("B19").Value
PathServices = Range("I26").Value
FileNameServices = Range("B26").Value
If Not IsWbOpen(FileNameFabrication) Then
'Test if directory or file exists:
If FileOrDirExists(PathFabrication & FileNameFabrication) Then
Workbooks.Open FileName:=PathFabrication & FileNameFabrication
Else: End If
End If
If Not IsWbOpen(FileNameMachineAndValveShop) Then
'Test if directory or file exists:
If FileOrDirExists(PathFabrication & FileNameFabrication) Then
Workbooks.Open FileName:=PathMachineAndValveShop & FileNameMachineAndValveShop
Else: End If
End If
If Not IsWbOpen(FileNameRiggersAndCranes) Then
'Test if directory or file exists:
If FileOrDirExists(PathFabrication & FileNameFabrication) Then
Workbooks.Open FileName:=PathRiggersAndCranes & FileNameRiggersAndCranes
Else: End If
End If
If Not IsWbOpen(FileNameServices) Then
'Test if directory or file exists:
If FileOrDirExists(PathFabrication & FileNameFabrication) Then
Workbooks.Open FileName:=PathServices & FileNameServices
Else: End If
End If
Windows(MasterFile).Activate
Range("P3") = ""
Range("A1").Select
Application.ScreenUpdating = True
Exit Sub ‘THE ERROR OCCURS WHEN EXECUTING THIS LINE
Errhandler:
'If an error occurs, display a message and end the macro:
MsgBox Err & ": " & Error(Err) & " error has occurred, macro execution is terminated."
Range("P3") = ""
Application.ScreenUpdating = True
End Sub
Bookmarks