dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,375
- Office Version
- 365
- 2016
- Platform
- Windows
I want to display a specific error message upon a set error being encountered. If error 53, or file not found appears, I will know the cause and solution.
I have some allocation sheet files that are stored on a network and I have some code within the ThisWorkbook module of those files. The code lets the user know if another user already has it open when the allocation file is opened.
These allocation sheet files act as a filing cabinet to store information. I have another file that is like a calculator to work out costs of jobs called my quoting tool. They are then copied across to the allocation sheet or filing cabinet for storage.
As I already mentioned, the above code works if the workbook is opened and someone else has it open. If enable macros has been selected by the user that has it open, the error message in the code will display but if they have not selected enable macros, the File not found error will be displayed which is not very meaningful. How can I change it so if that error occurs, I can display a message box instead of the file not found, asking the user to contact the person using "username" feature and get them to enable macros?
I have some allocation sheet files that are stored on a network and I have some code within the ThisWorkbook module of those files. The code lets the user know if another user already has it open when the allocation file is opened.
VBA Code:
Private Sub Workbook_Open()
Dim file1 As Integer
Dim strLine As String
file1 = FreeFile
If Not ActiveWorkbook.ReadOnly = True Then
'only add name to the usage log if the user has it locked
Open ThisWorkbook.Path & "\usage.log" For Append As #file1
Print #file1, Environ("USERNAME") & ". Please close all the additional workbooks that will be opened " _
& "without saving them. Then contact the user that has it open or wait until they are finished."
Close #file1
Else
'if someone else has the file open, find out who
Open ThisWorkbook.Path & "\usage.log" For Input Access Read As #file1
Do While Not EOF(file1)
Line Input #file1, strLine
Loop
Close #file1
MsgBox "The following user has the allocation sheets open: " & strLine
End If
End Sub
These allocation sheet files act as a filing cabinet to store information. I have another file that is like a calculator to work out costs of jobs called my quoting tool. They are then copied across to the allocation sheet or filing cabinet for storage.
As I already mentioned, the above code works if the workbook is opened and someone else has it open. If enable macros has been selected by the user that has it open, the error message in the code will display but if they have not selected enable macros, the File not found error will be displayed which is not very meaningful. How can I change it so if that error occurs, I can display a message box instead of the file not found, asking the user to contact the person using "username" feature and get them to enable macros?