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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2003 Error "Method 'Range' of Object '_Global' Failed"

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
This code is in Access 2003 which opens Excel and populates a sheet

Getting error: Method 'Range' of Object '_Global' Failed
on red line below.

It only happens if I run it and then close Excel and then re-run it. After a bit it seems to work again.

Code:
Dim objXL As New Excel.Application
    Dim objXLBook As Excel.Workbook

    objXL.Application.Visible = True
    PathToTemplate = "\\servero2\data files\TimeSheet2\AllTimeTemplate.xls"
    Set objXLBook = objXL.Workbooks.Open(PathToTemplate)
    
    With [COLOR=red]objXLBook.ActiveSheet.QueryTables.Add(Connection:="TEXT;F:\TimeSheet2\OHCPay.csv", Destination:=Range("A1"))[/color]
        .Name = "OHCPay" & Format(Now, "mm-dd-yy")
        .FieldNames = True
        .RowNumbers = False
	…
…
   End with
    Set objXL = Nothing
    Set objXLBook = Nothing


TIA

DougP
 




Doug, Please post CODE questions in Forum707.

Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 
..
Destination:=objXLBook.ActiveSheet.Range("A1")

combo
 
OK Skip I keep forgetting

combo,
Where am I putting that line?



DougP
 
In the red line. 'Range' is an excel worksheet's object and need to be marked so.

combo
 



Doug, HOW MANY TIMES?

Combo, he keeps coming back as we enable!

Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top