Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
LT LT is offline
external usenet poster
 
Posts: 2
Default Error 1004: Method 'Cells' of object '_Global' failed

I always get the above error when my code was executed the
second time continuously. If I only run it once, there are
no error.

-----------------------------------------
Public Sub CreateExcelFile()
Dim xlApp As Object
Dim xlWorkBook As Excel.Workbook

Set xlApp = CreateObject("Excel.Application")
Set xlWorkBook = xlApp.Workbooks.Open("C:\test.xls")

'This portion will format the column B into a text
column with leading zeros.
Dim i As Integer
Dim strT As String
i = 1
strT = ""
Do While Cells(i, "B").Text < ""
strT = Cells(i, "B").Text
Cells(i, "B").Formula = "=text(" & strT ", ""00000"")"
i = i + 1
Loop

xlWorkBook.SaveAs "C:\test1.xls", xlNormal
xlWorkBook.Close
Set xlWorkBook = Nothing
xlApp.Quit
Set xlApp = Nothing

End Sub
-----------------------------------------

I tried searching in the MS Knowledge Base & it returned
article 815406, suggesting to install a post-Office 2000
SP3 fix. However I can't find the link to this fix...

I'm not sure if the article is related to my error & how
do I overcome it?

Thanks!
LT.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Error 1004: Method 'Cells' of object '_Global' failed

code like this
Do While Cells(i, "B").Text < ""
strT = Cells(i, "B").Text
Cells(i, "B").Formula = "=text(" & strT ", ""00000"")"
i = i + 1
Loop

creates a reference to excel that can not be released until your application
closes.

First, if you are doing this from within Excel you don't need to do
createobject.
If you are doing it from word or access or some other application, then
qualify all you references

Do While xlapp.activesheet.Cells(i, "B").Text < ""
strT = xlapp.activesheet.Cells(i, "B").Text
xlapp.activesheet.Cells(i, "B").Formula = "=text(" & strT ", ""00000"")"
i = i + 1
Loop

Regards,
Tom Ogilvy

"LT" wrote in message
...
I always get the above error when my code was executed the
second time continuously. If I only run it once, there are
no error.

-----------------------------------------
Public Sub CreateExcelFile()
Dim xlApp As Object
Dim xlWorkBook As Excel.Workbook

Set xlApp = CreateObject("Excel.Application")
Set xlWorkBook = xlApp.Workbooks.Open("C:\test.xls")

'This portion will format the column B into a text
column with leading zeros.
Dim i As Integer
Dim strT As String
i = 1
strT = ""
Do While Cells(i, "B").Text < ""
strT = Cells(i, "B").Text
Cells(i, "B").Formula = "=text(" & strT ", ""00000"")"
i = i + 1
Loop

xlWorkBook.SaveAs "C:\test1.xls", xlNormal
xlWorkBook.Close
Set xlWorkBook = Nothing
xlApp.Quit
Set xlApp = Nothing

End Sub
-----------------------------------------

I tried searching in the MS Knowledge Base & it returned
article 815406, suggesting to install a post-Office 2000
SP3 fix. However I can't find the link to this fix...

I'm not sure if the article is related to my error & how
do I overcome it?

Thanks!
LT.



  #3   Report Post  
Posted to microsoft.public.excel.programming
LT LT is offline
external usenet poster
 
Posts: 2
Default Error 1004: Method 'Cells' of object '_Global' failed

Thanks Tom.

-----Original Message-----
code like this
Do While Cells(i, "B").Text < ""
strT = Cells(i, "B").Text
Cells(i, "B").Formula = "=text(" & strT ", ""00000"")"
i = i + 1
Loop

creates a reference to excel that can not be released

until your application
closes.

First, if you are doing this from within Excel you don't

need to do
createobject.
If you are doing it from word or access or some other

application, then
qualify all you references

Do While xlapp.activesheet.Cells(i, "B").Text < ""
strT = xlapp.activesheet.Cells(i, "B").Text
xlapp.activesheet.Cells(i, "B").Formula = "=text(" &

strT ", ""00000"")"
i = i + 1
Loop

Regards,
Tom Ogilvy

"LT" wrote in

message
...
I always get the above error when my code was executed

the
second time continuously. If I only run it once, there

are
no error.

-----------------------------------------
Public Sub CreateExcelFile()
Dim xlApp As Object
Dim xlWorkBook As Excel.Workbook

Set xlApp = CreateObject("Excel.Application")
Set xlWorkBook = xlApp.Workbooks.Open("C:\test.xls")

'This portion will format the column B into a text
column with leading zeros.
Dim i As Integer
Dim strT As String
i = 1
strT = ""
Do While Cells(i, "B").Text < ""
strT = Cells(i, "B").Text
Cells(i, "B").Formula = "=text(" &

strT ", ""00000"")"
i = i + 1
Loop

xlWorkBook.SaveAs "C:\test1.xls", xlNormal
xlWorkBook.Close
Set xlWorkBook = Nothing
xlApp.Quit
Set xlApp = Nothing

End Sub
-----------------------------------------

I tried searching in the MS Knowledge Base & it returned
article 815406, suggesting to install a post-Office 2000
SP3 fix. However I can't find the link to this fix...

I'm not sure if the article is related to my error & how
do I overcome it?

Thanks!
LT.



.

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
Charts.Add error '1004' Method 'Add' of object 'Sheets' failed Corey Charts and Charting in Excel 1 December 28th 06 02:15 PM
Method 'Range' of object '_global' failed higherlimits Excel Discussion (Misc queries) 3 June 23rd 06 06:16 PM
runtime error 1004 method range of object '_global failed valdesd Excel Discussion (Misc queries) 2 October 6th 05 07:26 PM
"Run-time error '1004'" Method 'Range' of object '_global' failed. haisat[_2_] Excel Programming 0 October 20th 03 12:13 PM


All times are GMT +1. The time now is 10:55 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"