blueishgray
Board Regular
- Joined
- Jul 8, 2004
- Messages
- 60
Hello
When I run the following code, I get a "Subscript Out of Range" error when the routine starts scanning through each "sht" of the selected workbook. (at the following part
I have looked at this for a while and cannot figure out what it cannot access the worksheets. below is the entire routine..
Any Ideas?
Thanks
Ian
[/code]
When I run the following code, I get a "Subscript Out of Range" error when the routine starts scanning through each "sht" of the selected workbook. (at the following part
Code:
For Each sht In Workbooks(FileName).Worksheets
If InStr(sht.Name, "Inv") <> 0 Then
checker = 1
GoTo two
End If
Next
I have looked at this for a while and cannot figure out what it cannot access the worksheets. below is the entire routine..
Any Ideas?
Thanks
Ian
Code:
Sub Testing()
Dim checker As Integer
Dim sht As Worksheet
Dim FilePath As Variant, FileName As Variant
FilePath = Application.GetOpenFilename()
If FilePath = False Then
MsgBox "Cancelled"
GoTo one
End If
FileName = Mid(FilePath, InStrRev(FilePath, "\") + 1)
If InStr(FileName, "TimeSheet") = 0 Then
MsgBox "Not a Valid Selection"
GoTo one
End If
checker = 0
For Each sht In Workbooks(FileName).Worksheets
If InStr(sht.Name, "Inv") <> 0 Then
checker = 1
GoTo two
End If
Next
two:
If checker <> 1 Then
MsgBox "No Invoices are present in selected file."
GoTo one
End If
'Workbooks.Open FileName:=FilePath
one:
End Sub