Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel OLE Problem 2

Status
Not open for further replies.

matzos

Programmer
Aug 22, 2001
38
US
I am trying to export an Access report out to Excel. I am using OLE to do this. It is moving along pretty smoothly except that I am getting an error - but not all of the time - over this section of code which is only intended to cut headers from one place to another:

.Range("A6").Select
.Selection.Cut Destination:=Range("A1")
.Range("B6").Select
.Selection.Cut Destination:=Range("A2")
.Range("C6").Select
.Selection.Cut Destination:=Range("A3")
.Range("E6").Select
.Selection.Cut Destination:=Range("A4")

(This exists within a With statement for Object xlObject)

The error that I get is:

Run Time Error #1004
Method 'Range' of object '_Global' failed.

Again, I get this error only about 50% of the time that I run this OLE macro. I copied the code, for the most part, from a macro that I created in Excel. Are there modifications that I have to make to get Access to recognize it? If so, why does it recognize it sometimes?

Please help! thanks.
 
Make sure you properly instanstiate Excel.

See the following articles at the MS KB

Q178510 PRB: Excel Automation Method of Object '_Global'Failed
Q167223 Microsoft Office 97 Automation Help File Available
For additional information about the Automation of Office applications, click the article number below to view the article in the Microsoft Knowledge Base:



xlObject.Range("A6").Select
xlObject.Selection.Cut Destination:=Range("A1")

I know you used the with, but sometimes this works. Escpicially on the right hand side Tyrone Lumley
augerinn@gte.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top