Open multiple workbooks from directory path

  • Thread starter Thread starter Len
  • Start date Start date
L

Len

Hi,

I tried to develop codes below and it prompts mismatch error message

Dim sPath As String
Dim k As Long
Dim myWB As Workbooks
Dim arrk

sPath = "D:\My Documents\P\Bank\CVB\"
arrk = Array("CVB Bank recon.xls", "GL.xls", "CVB.xls",
"GLformat.xls", "GL.unpchq.xls")
For k = 0 To UBound(arrk)
Set myWB = Nothing
Set myWB = Workbooks.Open(Filename:="D:\My Documents\P\Bank\CVB\"
& arrk(k))
If Err.Number = 0 Then
MsgBox "Workbook " & arrk(k) & " not found, process end "
Exit Sub
On Error GoTo 0
Else
Workbooks.Open Filename:="D:\Onglt Documents\HELP\Bank\RHB\" &
arrk(k)
End If
Next k

Any help will be appreciated and thanks in advance

Regards
Len
 
Sorry, please discard the earlier incorrect codes and replace with the
following codes

Dim sPath As String
Dim k As Long
Dim myWB As Workbooks
Dim arrk

sPath = "D:\My Documents\P\Bank\CVB\"
arrk = Array("CVB Bank recon.xls", "GL.xls", "CVB.xls",
"GLformat.xls", "GL.unpchq.xls")
For k = 0 To UBound(arrk)
Set myWB = Nothing
Set myWB = Workbooks.Open(Filename:="D:\My Documents\P\Bank\CVB\"
& arrk(k))
If Err.Number = 0 Then
MsgBox "Workbook " & arrk(k) & " not found, process end "
Exit Sub
On Error GoTo 0
Else
Workbooks.Open Filename:="D:\My Documents\P\Bank\CVB\" & arrk(k))
End If
Next k
 
Back
Top