ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding New Workbook (https://www.excelbanter.com/excel-programming/398190-adding-new-workbook.html)

C Hayes

Adding New Workbook
 
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



Bob Phillips

Adding New Workbook
 
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)

"C Hayes" wrote in message
...
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





C Hayes

Adding New Workbook
 
Thank you

"Bob Phillips" wrote:

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)

"C Hayes" wrote in message
...
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







All times are GMT +1. The time now is 02:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com