Adding New Workbook

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to manipulate a new worksheet from Access. When running this
code the first time the sheet is created and manipulated with no problem. If
I attempt to rerun the code it fails.

Run-time Error '1004':
Method 'Range' of Object '_Global' failed

any ideas as to my instancing the sheet? maybe the wrong method.


Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWrkbk = xlApp.Workbooks.Add
ii = 1
For i = 1 To 15 Step 2
Range("A" & i) = "Pre " & ii
ii = ii + 1
Next i
 
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWrkbk = xlApp.Workbooks.Add
ii = 1
For i = 1 To 15 Step 2
xlWrkbk.Activesheet.Range("A" & i) = "Pre " & ii
ii = ii + 1
Next i



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Thank you

Bob Phillips said:
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWrkbk = xlApp.Workbooks.Add
ii = 1
For i = 1 To 15 Step 2
xlWrkbk.Activesheet.Range("A" & i) = "Pre " & ii
ii = ii + 1
Next i



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top