I'm pretty new to OLE Automation so bear with me!
I'm intending to create a complex Excel spreadsheet that I want to pump values from Access into on a cell by cell basis.
I've created a quick Access VBA test project that opens my .xls file "oletest", changes focus in Excel to "Sheet1" and pumps a hardcoded value into cell (1,1). It then saves the .xls file under another name and attempts to tidy itself up:
Set xlObject = CreateObject("excel.application"
xlObject.Visible = True
xlObject.Application.Workbooks.Open "c:\oletest.xls"
Worksheets("Sheet1"
.Activate
Worksheets("Sheet1"
.Cells(1, 1).Value = "Test 123"
Worksheets("Sheet1"
.SaveAs ("c:\anothertest.xls"
xlObject.Application.Workbooks.Close
xlObject.Quit
The problem I have is that the first time I run the project it works. The second time I get:
"Run-time error '1004':
Method 'Worksheets' of object '_Global' failed"
This is caused by the line:
Worksheets("Sheet1"
.Activate
If I click on help nothing happens.
I'm assuming that I'm not tidying up Excel properly when I close it down but I have no idea what else I should be doing.
Help as always is appreciated!
I'm intending to create a complex Excel spreadsheet that I want to pump values from Access into on a cell by cell basis.
I've created a quick Access VBA test project that opens my .xls file "oletest", changes focus in Excel to "Sheet1" and pumps a hardcoded value into cell (1,1). It then saves the .xls file under another name and attempts to tidy itself up:
Set xlObject = CreateObject("excel.application"
xlObject.Visible = True
xlObject.Application.Workbooks.Open "c:\oletest.xls"
Worksheets("Sheet1"
Worksheets("Sheet1"
Worksheets("Sheet1"
xlObject.Application.Workbooks.Close
xlObject.Quit
The problem I have is that the first time I run the project it works. The second time I get:
"Run-time error '1004':
Method 'Worksheets' of object '_Global' failed"
This is caused by the line:
Worksheets("Sheet1"
If I click on help nothing happens.
I'm assuming that I'm not tidying up Excel properly when I close it down but I have no idea what else I should be doing.
Help as always is appreciated!