Question : Check if workbook is open and then close

Ok, after reviewing several samples on-line, the attached theoriecally should work.  I want to check to see if the workbook is open, if it, then save and close.  But I keep getting a subscript out of range error message.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Public Sub FileClose(strReportDate As String)
Dim strPath As String
Dim wbkName As String
Dim wbk As Workbook
wbkName = "Intl_Index_" & strReportDate & ".xls"
strPath = DLookup("Directory", "tblDirectory", "Type = 'strPath' ")
    
    On Error Resume Next
    Set wbk = Workbooks("Intl_Index_" & strReportDate & ".xls")
     
    If wbk Is Nothing Then
        'Do nothing
    Else
        wbk.Close
    End If

End Sub

Answer : Check if workbook is open and then close

Now that I better understand the problem, try this:

1:
2:
3:
4:
5:
6:
7:
8:
9:
Dim excelApp As Excel.Application
Dim wkb As WorkBook
  
Set excelApp = GetObject(, "Excel.Application")
For Each wkb In excelApp.Workbooks
    If wkb.Name = "Intl_Index_" & strReportDate & ".xls" Then
        wkb.Close
    End If
Next
Random Solutions  
 
programming4us programming4us