473,583 Members | 2,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Method 'Range' of object '_Global' failed

I get this Run-Time Error 1004 whenevery the following code runs:

On Error GoTo XLSheet2
Set objXL = CreateObject("E xcel.Applicatio n")
With objXL
Set objWkb = .Workbooks.Open (strPath)
With objWkb
Set objSht1 = .Worksheets("Ac tual_Releases_b y_Week")
With objSht1
If IsNull(.Range(" A2")) Or .Range("A2") = "" Then GoTo
XLSheet2
Range("A2:B2"). Select
Range(Selection , Selection.End(x lDown)).Select
Selection.Delet e Shift:=xlUp
Range("A2").Sel ect
End With
XLSheet2:
On Error GoTo 0
On Error GoTo XLTransfer
Set objSht2 = .Worksheets("Dr awing_Recovery_ by_Week")
With objSht2
If IsNull(.Range(" A2")) Or .Range("A2") = "" Then GoTo
XLTransfer
'************** *************** *************** *************** *************** *************** *******
HERE'S WHERE THE ERROR OCCURS...
.Range("A2:B2") .Select
Range(Selection , Selection.End(x lDown)).Select
Selection.Delet e Shift:=xlUp
Range("A2").Sel ect
End With
.Save
XLTransfer:
.Close (True)
End With
.Quit
End With
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
DoCmd.TransferS preadsheet acExport, 5, "Actual Releases by Week", strPath,
True, ""
DoCmd.TransferS preadsheet acExport, 5, "Drawing Recovery by Week",
strPath, True, ""
MsgBox "Successful ly updated " & strFile, vbInformation + vbOKOnly, _
"Release Chart Data Update"
End If
Set objXL = New Excel.Applicati on
objXL.Visible = True
With objXL
.Visible = True
Set objWkb = .Workbooks.Open (strPath)
End With
Set objWkb = Nothing
Set objXL = Nothing

The strangest thing about it is that the 1st error handler works and shoots
the code down to "XLSheet2:"
But at the point where I get the msg, the error handler is ignored and I get
a run-time error 1004. As you can see, I've tried to close the workbook and
reset the objects in order to open it for the user, as opposed to having him
hunt for it in a directory on the server. Obviously, if he's gone to all the
trouble to update the data in the chart, he'd probably like to take a look at
it. When the code 1st runs, I check in Task Manager and Excel is not running
until my code sets the objXL. Pls advise.
--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #1
4 12906
Bill:

You need to activate objSht2 before selecting a range on the sheet. If you
add the following line, the error does not occur:

objsht2.Activat e 'Add this line before the following

HERE'S WHERE THE ERROR OCCURS...
.Range("A2:B2") .Select
Range(Selection , Selection.End(x lDown)).Select
Selection.Delet e Shift:=xlUp
--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.
"Bill R via AccessMonster.c om" <fo***@AccessMo nster.com> wrote in message
news:51******** ***@AccessMonst er.com...
I get this Run-Time Error 1004 whenevery the following code runs:

On Error GoTo XLSheet2
Set objXL = CreateObject("E xcel.Applicatio n")
With objXL
Set objWkb = .Workbooks.Open (strPath)
With objWkb
Set objSht1 = .Worksheets("Ac tual_Releases_b y_Week")
With objSht1
If IsNull(.Range(" A2")) Or .Range("A2") = "" Then GoTo
XLSheet2
Range("A2:B2"). Select
Range(Selection , Selection.End(x lDown)).Select
Selection.Delet e Shift:=xlUp
Range("A2").Sel ect
End With
XLSheet2:
On Error GoTo 0
On Error GoTo XLTransfer
Set objSht2 = .Worksheets("Dr awing_Recovery_ by_Week")
With objSht2
If IsNull(.Range(" A2")) Or .Range("A2") = "" Then GoTo
XLTransfer
'************** *************** *************** *************** *************** *************** *******
HERE'S WHERE THE ERROR OCCURS...
.Range("A2:B2") .Select
Range(Selection , Selection.End(x lDown)).Select
Selection.Delet e Shift:=xlUp
Range("A2").Sel ect
End With
.Save
XLTransfer:
.Close (True)
End With
.Quit
End With
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
DoCmd.TransferS preadsheet acExport, 5, "Actual Releases by Week",
strPath,
True, ""
DoCmd.TransferS preadsheet acExport, 5, "Drawing Recovery by Week",
strPath, True, ""
MsgBox "Successful ly updated " & strFile, vbInformation + vbOKOnly, _
"Release Chart Data Update"
End If
Set objXL = New Excel.Applicati on
objXL.Visible = True
With objXL
.Visible = True
Set objWkb = .Workbooks.Open (strPath)
End With
Set objWkb = Nothing
Set objXL = Nothing

The strangest thing about it is that the 1st error handler works and shoots
the code down to "XLSheet2:"
But at the point where I get the msg, the error handler is ignored and I get
a run-time error 1004. As you can see, I've tried to close the workbook and
reset the objects in order to open it for the user, as opposed to having him
hunt for it in a directory on the server. Obviously, if he's gone to all the
trouble to update the data in the chart, he'd probably like to take a look
at
it. When the code 1st runs, I check in Task Manager and Excel is not running
until my code sets the objXL. Pls advise.
--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #2
David,

Thanks a million!

BTW, do you have any idea why the error handler failed to handle the error? I
have "Break for unhandled errors" selected in tools/options.

Any suggestions for opening the workbook after the data is updated?

Thanks,

Bill

David Lloyd wrote:
Bill:

You need to activate objSht2 before selecting a range on the sheet. If you
add the following line, the error does not occur:

objsht2.Activa te 'Add this line before the following

HERE'S WHERE THE ERROR OCCURS...
.Range("A2:B2") .Select
Range(Selection , Selection.End(x lDown)).Select
Selection.Delet e Shift:=xlUp
The strangest thing about it is that the 1st error handler works and shoots
the code down to "XLSheet2:"
But at the point where I get the msg, the error handler is ignored and I get
a run-time error 1004. As you can see, I've tried to close the workbook and
reset the objects in order to open it for the user, as opposed to having him
hunt for it in a directory on the server. Obviously, if he's gone to all the
trouble to update the data in the chart, he'd probably like to take a look
at
it. When the code 1st runs, I check in Task Manager and Excel is not running
until my code sets the objXL. Pls advise.

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #3
David,

Is the technique I'm using valid? I want to delete the data in the workbook
because it's conceivable that the new data might have fewer records than the
old, and I don't want to leave old records at the bottom of the table.
I've used XLCopyFromRecor dset code in the past, but opted for
TransferSpreads heet for no compelling reason. Is that a mistake?
Finally, I want to open the newly updated workbook. I think I need to close
it for the TransferSpreads heet function to work, and then reopen it. So I
don't want to .quit the workbook, but I need to empty the variables, right?

Thanks,

Bill

David Lloyd wrote:
Bill:

You need to activate objSht2 before selecting a range on the sheet. If you
add the following line, the error does not occur:

objsht2.Activa te 'Add this line before the following

HERE'S WHERE THE ERROR OCCURS...
.Range("A2:B2") .Select
Range(Selection , Selection.End(x lDown)).Select
Selection.Delet e Shift:=xlUp

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #4
Bill:

The error handler will fail to handle to error in section XLSheet2 if it was
sent to that section by a preceding error. If no error occurs prior to
section XLSheet2 then the error handling does work. My suggestion would be
to structure the procedure so that it exits in the event of an error.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.
"Bill R via AccessMonster.c om" <fo***@AccessMo nster.com> wrote in message
news:51******** ***@AccessMonst er.com...
David,

Thanks a million!

BTW, do you have any idea why the error handler failed to handle the error?
I
have "Break for unhandled errors" selected in tools/options.

Any suggestions for opening the workbook after the data is updated?

Thanks,

Bill

David Lloyd wrote:
Bill:

You need to activate objSht2 before selecting a range on the sheet. If you
add the following line, the error does not occur:

objsht2.Activa te 'Add this line before the following

HERE'S WHERE THE ERROR OCCURS...
.Range("A2:B2") .Select
Range(Selection , Selection.End(x lDown)).Select
Selection.Delet e Shift:=xlUp
The strangest thing about it is that the 1st error handler works and shoots
the code down to "XLSheet2:"
But at the point where I get the msg, the error handler is ignored and I
get
a run-time error 1004. As you can see, I've tried to close the workbook and
reset the objects in order to open it for the user, as opposed to having
him
hunt for it in a directory on the server. Obviously, if he's gone to all
the
trouble to update the data in the chart, he'd probably like to take a look
at
it. When the code 1st runs, I check in Task Manager and Excel is not
running
until my code sets the objXL. Pls advise.

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6256
by: richilli | last post by:
Hi Any help on this would be appreciated cos its driving me insane. I have a function in VB.NET that takes in an excel range and tries to delete rows where the first column starts with a string. Only it doesnt work and all i get is "Delete method of Range class failed" whatever i do. Any suggestions?
7
22106
by: Ike | last post by:
Can someone please illuminate to me why, in the following snippet of script, the alert statement in the try-catch gives me ? The file 'http://localhost:1222/roomx1/getdata.php' truly does exist. I'm really lost here and would appreciate anyone's good eye. Thanks, Ike if(typeof window.ActiveXObject != 'undefined'){ req = new...
35
2275
by: eyoung | last post by:
I call a function that takes the unit price and quantity ordered to create an amount...it looks something like this. function calculateCost() { quantity=document.RFO.quantity.value; unitPrice=document.RFO.unitPrice.value; total=0; if(isPositiveInteger(quantity)) {
2
7245
by: smichr | last post by:
It seems to me that the indices() method for slices is could be improved. Right now it gives back concrete indices for a range of length n. That is, it does not return any None values. Using an example from clpy about this the indices for a 'None, None, -2' slice for a range of length 10 are given as '9, -1, -2'. The problem is that these...
4
7137
by: dilau | last post by:
I have a problem. The error in subject appear when i run the macro Can u tell me why Case "CENTRALIZATOR SURVEY" Dim SHT As Object Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY") SHT.Cells(10, 1) = UCase(n) If IsEmpty(SHT.Cells(11,...
1
5098
by: Socko | last post by:
I'm trying to fix an sub routine in an VB module that basically reads in a MS database and writes it to an Excel Spread sheet. It works just fine except that the data isn't sorted correctly. I have no experience at all in excel or the vb code to access excel. I found a few lines of code by searching on how to sort in vb for excel and the code...
15
2038
by: Bob | last post by:
Is there anyway to access the global object from inside a function other than doing a "var _global = this;" before declaring the function? Thanks
4
15477
by: ielamrani | last post by:
Hi, I am getting this error when I try to export to an excel sheet. When I click on a button to export the first time it's fine, I rename the exported excel sheet and I try to export it again and I get the error: Runtime Error 1004: Method ‘Cells’ of Object ‘_Global’ failed It highlight this line: Range("A1:L1").Select sorry the code behind...
0
7811
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8159
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8314
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8185
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6571
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5689
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3811
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3836
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.