W
wellie
I'm trying to have a loop to open a set of workbook one at
a time to sort and copy some data out and then close it.
The following code ONLY works for the first workbook, it
fails when it tries to open the 2nd workbook and prompted
me "Run-time error '1004' Application-defined or object-
defined error."
Can someone please tell me what I need to do to have s.t.
I can open this set of workbooks in a loop ?
Thanks in advance for any assistance.
dim wkbk as Workbook
dim fPathname as String
For i=1 to 5
fPathname = ("c:\Myfile"+cstr(i)+".xs"
Set wkbk = Workbooks.Open(fPathname)
j = 10
Do While wkbk.Sheets(1).Cells(j, 8).Value > 0
j = j + 1
Loop
MsgBox (fPathname + " contains " + CStr(j - 1) + " rows
of data.")
' *** Copy data and other stuff here.
Application.DisplayAlerts = False
wkbk.Close fPathname
Application.DisplayAlerts = True
Set wkbk = Nothing
Next i
a time to sort and copy some data out and then close it.
The following code ONLY works for the first workbook, it
fails when it tries to open the 2nd workbook and prompted
me "Run-time error '1004' Application-defined or object-
defined error."
Can someone please tell me what I need to do to have s.t.
I can open this set of workbooks in a loop ?
Thanks in advance for any assistance.
dim wkbk as Workbook
dim fPathname as String
For i=1 to 5
fPathname = ("c:\Myfile"+cstr(i)+".xs"
Set wkbk = Workbooks.Open(fPathname)
j = 10
Do While wkbk.Sheets(1).Cells(j, 8).Value > 0
j = j + 1
Loop
MsgBox (fPathname + " contains " + CStr(j - 1) + " rows
of data.")
' *** Copy data and other stuff here.
Application.DisplayAlerts = False
wkbk.Close fPathname
Application.DisplayAlerts = True
Set wkbk = Nothing
Next i