Hi
I have the following macro but im trying to get it to notify me if its read only when opening.
How do I do this and can it be tidied up?
Declare the variables
Dim MyPath As String
Dim MyFile As String
Dim LatestFile As String
Dim LMD As Date
'Specify the path to the folder
MyPath = "T:\Passenger Accounts\SHARED\passacc\Excel\passacc\Tableau Data"
'Make sure that the path ends in a backslash
If Right(MyPath, 1) <> "" Then MyPath = MyPath & ""
'Get the first Excel file from the folder
MyFile = Dir(MyPath & "*.xlsx", vbNormal)
'If no files were found, exit the sub
If Len(MyFile) = 0 Then
MsgBox "No files were found...", vbExclamation
Exit Sub
End If
LatestFile = ""
'Loop through each Excel file in the folder
Do While Len(MyFile) > 0
If MyFile > LatestFile Then
LatestFile = MyFile
End If
'Get the next Excel file from the folder
MyFile = Dir
Loop
'Open the latest file
Workbooks.Open MyPath & LatestFile
End Sub
I have the following macro but im trying to get it to notify me if its read only when opening.
How do I do this and can it be tidied up?
Declare the variables
Dim MyPath As String
Dim MyFile As String
Dim LatestFile As String
Dim LMD As Date
'Specify the path to the folder
MyPath = "T:\Passenger Accounts\SHARED\passacc\Excel\passacc\Tableau Data"
'Make sure that the path ends in a backslash
If Right(MyPath, 1) <> "" Then MyPath = MyPath & ""
'Get the first Excel file from the folder
MyFile = Dir(MyPath & "*.xlsx", vbNormal)
'If no files were found, exit the sub
If Len(MyFile) = 0 Then
MsgBox "No files were found...", vbExclamation
Exit Sub
End If
LatestFile = ""
'Loop through each Excel file in the folder
Do While Len(MyFile) > 0
If MyFile > LatestFile Then
LatestFile = MyFile
End If
'Get the next Excel file from the folder
MyFile = Dir
Loop
'Open the latest file
Workbooks.Open MyPath & LatestFile
End Sub
Last edited: