Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel failed on second trip - Error: 1004

I create a routine that will read an excel file and send the content to a
text file. If there's only one excel file, the routine works. If there're
multiple, then the second call to that sub will failed with 1004 -
Application-defined or object-defined error
here is partial code below. PLEASE HELP.

Dim objExcel As Excel.Application
......

Set objExcel = New Excel.Application
objExcel.Workbooks.Open strFileName -- passed from calling routine
For R = 2 To Range("A65536").End(xlUp).Row -- FAIL HERE
.........
next R

objExcel.Quit
Set objExcel = Nothing


The second time, the error happend on "For" statement, the open statement
does not failed. I add "objExcel.Worksheets("Sheet1").Activate" as test, it
failed.

There's no EXCEL object from task manager.




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Excel failed on second trip - Error: 1004

If you are automating Excel you need to qualify everything back to the
application object

Set objWb = objExcel.Workbooks.Open(strFileName)
For R = 2 To objWb.Worksheets(1).Range("A65536").etc

or you might be able to get away with
objExcel.ActiveSheet.Range(etc
(if sure the correct wb is active)

Regards,
Peter T




"Jim Pan" wrote in message
...
I create a routine that will read an excel file and send the content to a
text file. If there's only one excel file, the routine works. If
there're
multiple, then the second call to that sub will failed with 1004 -
Application-defined or object-defined error
here is partial code below. PLEASE HELP.

Dim objExcel As Excel.Application
.....

Set objExcel = New Excel.Application
objExcel.Workbooks.Open strFileName -- passed from calling routine
For R = 2 To Range("A65536").End(xlUp).Row -- FAIL HERE
........
next R

objExcel.Quit
Set objExcel = Nothing


The second time, the error happend on "For" statement, the open statement
does not failed. I add "objExcel.Worksheets("Sheet1").Activate" as test,
it
failed.

There's no EXCEL object from task manager.






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel failed on second trip - Error: 1004

I have qualify the worksheet also, after that, everything worked. Thanks
for pointed out simple mistake. I was trying to have minimum code as my vb
module grew large.

Thanks!

"Peter T" wrote:

If you are automating Excel you need to qualify everything back to the
application object

Set objWb = objExcel.Workbooks.Open(strFileName)
For R = 2 To objWb.Worksheets(1).Range("A65536").etc

or you might be able to get away with
objExcel.ActiveSheet.Range(etc
(if sure the correct wb is active)

Regards,
Peter T




"Jim Pan" wrote in message
...
I create a routine that will read an excel file and send the content to a
text file. If there's only one excel file, the routine works. If
there're
multiple, then the second call to that sub will failed with 1004 -
Application-defined or object-defined error
here is partial code below. PLEASE HELP.

Dim objExcel As Excel.Application
.....

Set objExcel = New Excel.Application
objExcel.Workbooks.Open strFileName -- passed from calling routine
For R = 2 To Range("A65536").End(xlUp).Row -- FAIL HERE
........
next R

objExcel.Quit
Set objExcel = Nothing


The second time, the error happend on "For" statement, the open statement
does not failed. I add "objExcel.Worksheets("Sheet1").Activate" as test,
it
failed.

There's no EXCEL object from task manager.







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Run time error 1004, range of object_global failed in-over-his-head-bill Excel Programming 9 July 12th 06 05:46 AM
error 1004 Method SaveAs of Workbook failed Maury Markowitz Excel Programming 2 October 25th 05 08:45 PM
runtime error '1004' object '_Global' failed Jim in Spokane[_2_] Excel Programming 0 August 3rd 05 12:16 AM
Error Excel: 1004 SaveAs method of Workbook class failed sebastien Excel Programming 0 August 13th 03 09:59 AM
HELP!! Excel 2000 Copy of worksheet class failed run time Error 1004 Martin[_6_] Excel Programming 1 August 2nd 03 03:16 PM


All times are GMT +1. The time now is 10:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"