Sub OpenBooks()
Dim cel As Range
For Each cel In [Days]
Dim dir As String, wb As String
dir = "C:\Documents and Settings\T0122059\Desktop\XYZBooks\Files\"
On Error GoTo here
wb = cel & "Next.xls"
Workbooks.Open Filename:=dir & wb
[A1] = 22
here:
On Error GoTo there
wb = cel & ".xls"
Workbooks.Open Filename:=dir & wb
[A1] = 22
there:
ThisWorkbook.Activate
Next
End Sub
Sub OpenBooks()
Dim cel As Range
Dim foundx As Boolean
For Each cel In [Days]
Dim dirx As String
dirx = "C:\Documents and Settings\T0122059\Desktop\XYZBooks\Files\"
foundx = False
If Dir(dirx & cel & "Next.xls") <> "" Then
Workbooks.Open Filename:=dirx & cel.Value & "Next.xls"
[A1] = 22
foundx = True
End If
If Dir(dirx & cel & ".xls") <> "" Then
Workbooks.Open Filename:=dirx & cel & ".xls"
[A1] = 22
foundx = True
End If
If Not foundx Then MsgBox ("""" & cel & """ not found.")
Next
ThisWorkbook.Activate
End Sub
ASKER
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
TRUSTED BY
Or can you upload the file only with the days range. You can delete everything else.