473,487 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
Create 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("Excel.Application")
With objXL
Set objWkb = .Workbooks.Open(strPath)
With objWkb
Set objSht1 = .Worksheets("Actual_Releases_by_Week")
With objSht1
If IsNull(.Range("A2")) Or .Range("A2") = "" Then GoTo
XLSheet2
Range("A2:B2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Range("A2").Select
End With
XLSheet2:
On Error GoTo 0
On Error GoTo XLTransfer
Set objSht2 = .Worksheets("Drawing_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(xlDown)).Select
Selection.Delete Shift:=xlUp
Range("A2").Select
End With
.Save
XLTransfer:
.Close (True)
End With
.Quit
End With
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
DoCmd.TransferSpreadsheet acExport, 5, "Actual Releases by Week", strPath,
True, ""
DoCmd.TransferSpreadsheet acExport, 5, "Drawing Recovery by Week",
strPath, True, ""
MsgBox "Successfully updated " & strFile, vbInformation + vbOKOnly, _
"Release Chart Data Update"
End If
Set objXL = New Excel.Application
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.com
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #1
4 12893
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.Activate 'Add this line before the following

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

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

On Error GoTo XLSheet2
Set objXL = CreateObject("Excel.Application")
With objXL
Set objWkb = .Workbooks.Open(strPath)
With objWkb
Set objSht1 = .Worksheets("Actual_Releases_by_Week")
With objSht1
If IsNull(.Range("A2")) Or .Range("A2") = "" Then GoTo
XLSheet2
Range("A2:B2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Range("A2").Select
End With
XLSheet2:
On Error GoTo 0
On Error GoTo XLTransfer
Set objSht2 = .Worksheets("Drawing_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(xlDown)).Select
Selection.Delete Shift:=xlUp
Range("A2").Select
End With
.Save
XLTransfer:
.Close (True)
End With
.Quit
End With
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
DoCmd.TransferSpreadsheet acExport, 5, "Actual Releases by Week",
strPath,
True, ""
DoCmd.TransferSpreadsheet acExport, 5, "Drawing Recovery by Week",
strPath, True, ""
MsgBox "Successfully updated " & strFile, vbInformation + vbOKOnly, _
"Release Chart Data Update"
End If
Set objXL = New Excel.Application
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.com
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.Activate 'Add this line before the following

HERE'S WHERE THE ERROR OCCURS...
.Range("A2:B2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete 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.com
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 XLCopyFromRecordset code in the past, but opted for
TransferSpreadsheet 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 TransferSpreadsheet 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.Activate 'Add this line before the following

HERE'S WHERE THE ERROR OCCURS...
.Range("A2:B2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

--
Message posted via AccessMonster.com
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.com" <fo***@AccessMonster.com> wrote in message
news:51***********@AccessMonster.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.Activate 'Add this line before the following

HERE'S WHERE THE ERROR OCCURS...
.Range("A2:B2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete 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.com
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
6242
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...
7
22100
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....
35
2244
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;...
2
7234
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...
4
7134
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...
1
5095
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...
15
2022
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
15461
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...
0
6967
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...
0
7181
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...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7349
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...
0
5442
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,...
1
4874
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...
0
3076
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...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.