Johnny Thunder
Well-known Member
- Joined
- Apr 9, 2010
- Messages
- 693
- Office Version
- 2016
- Platform
- MacOS
Hi guys,
working on updating a workbook that contains some code that was inserted into a UserForm.
I am having an issue because the code looks in a specific folder with both .xls and .xlsm file and the usual "*.xls*" wildcard doesn't seem to be working?
I have tried both "*xl*" and "*xls*" as updates to the line below in question but I keep getting a Error:9 Subscript out of range error message.
If there was a way to say try .xls first, if it doesn't work then try .xlsm next that would probably fix the issue.
Any help is appreciated.
working on updating a workbook that contains some code that was inserted into a UserForm.
I am having an issue because the code looks in a specific folder with both .xls and .xlsm file and the usual "*.xls*" wildcard doesn't seem to be working?
I have tried both "*xl*" and "*xls*" as updates to the line below in question but I keep getting a Error:9 Subscript out of range error message.
If there was a way to say try .xls first, if it doesn't work then try .xlsm next that would probably fix the issue.
Any help is appreciated.
Code:
Private Sub Run_Update()
On Error GoTo ErrorHandler:
Application.StatusBar = "TBT Update File is starting..."
vAPSTATE1 = Application.Calculation
Application.ScreenUpdating = False
Application.Cursor = xlNormal
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
vERRORCOUNT = 0
Set vUSHT = ThisWorkbook.Sheets("Admin")
If CheckBoxAdmin1 = True Then
For Each vCELL In Range("LISTTERRITORYNAME").Cells
vFILEPATH = ThisWorkbook.Path & "\"
vFILEWKBK = Range("TBTPREFIX").Value & " - " & vCELL.Value & "*.xls*" 'This is the line that is causing the issue
vFILENAME = vFILEPATH & vFILEWKBK
UpdateTasks vFILENAME, vFILEWKBK
Next
MsgBox "Your files have been updated!", vbInformation, "All Done!"
Else
vFILEPATH = ThisWorkbook.Path & "\"
vFILEWKBK = txtFileName
vFILENAME = vFILEPATH & vFILEWKBK
UpdateTasks vFILENAME, vFILEWKBK
End If
ExitSub:
Application.DisplayAlerts = True
Application.Calculation = vAPSTATE1
Application.Cursor = xlNormal
Application.ScreenUpdating = True
Application.StatusBar = False
Set vWKBK = Nothing
Unload Me
Exit Sub
ErrorHandler:
vERRORCOUNT = vERRORCOUNT + 1
MsgBox "Error: " & Err.Number & " - " & Err.Description & vbNewLine & vbNewLine & _
"An error has occurred while trying to update your " & vbNewLine & _
"file. Please contact your file administrator before " & vbNewLine & _
"continuing.", vbCritical
GoTo ExitSub
End Sub