Bilbo_Baggins_Esq
Registered User.
- Local time
- Today, 08:30
- Joined
- Jul 5, 2007
- Messages
- 586
Hi All,
I'm pretty sure i know why this is happening, but I cannot seem to sort out the solution.
I have the below code.
It is running from Acccess 2010.
It runs fine, the first time through.
Then it errors out on the red line on the second loop.
Like I said, it runs FINE the first time though the loop.
After the first time, is when it throws an error on either one of the two red lines.
I've tried quite a few ways to be more specific (to avoid the _Global), but nothing seems to work for me.
Any Ideas?
I'm pretty sure i know why this is happening, but I cannot seem to sort out the solution.
I have the below code.
It is running from Acccess 2010.
It runs fine, the first time through.
Then it errors out on the red line on the second loop.
Code:
Private Sub DoExcelOperationsTesting_Original()
Dim ExcelInst As Excel.Application
MsgBox "DoExcelOperationsTesting"
Set ws = DBEngine.Workspaces(0)
Set db = ws.Databases(0)
Set rsExcelOpsResults = db.OpenRecordset("tbl_Results_ExcelOps", dbOpenDynaset)
rsExcelOpsResults.AddNew
For RunNumber = 0 To 9
Set ExcelInst = CreateObject("Excel.Application")
With ExcelInst
.Visible = True
.Workbooks.Add
.Calculation = xlCalculationManual
End With
ExcelInst.Worksheets("Sheet1").Cells(1, 1).Select
ExcelInst.Worksheets("Sheet1").Cells(1, 1).Formula = "=ROW()+COLUMN()"
Start = Timer
[COLOR="Red"][B]ExcelInst.Range(Cells(1, 1), Cells(1, (RunNumber + 1) * 100)).Select[/B][/COLOR]
Selection.FillRight
Finish = Timer
rsExcelOpsResults.Fields(((RunNumber + 1) * 1) + 1).Value = Finish - Start
Start = Timer
[COLOR="Red"][B]ExcelInst.Range(Cells(1, 1), Cells((RunNumber + 1) * 100, (RunNumber + 1) * 100)).Select[/B][/COLOR]
Selection.FillDown
Finish = Timer
rsExcelOpsResults.Fields(((RunNumber + 2) * 1) + 1).Value = Finish - Start
Start = Timer
Calculate
Finish = Timer
rsExcelOpsResults.Fields(((RunNumber + 3) * 1) + 1).Value = Finish - Start
ExcelInst.ActiveWorkbook.Close (False)
Set ExcelWkb = Nothing
ExcelInst.Quit
Set ExcelInst = Nothing
Next RunNumber
rsExcelOpsResults.Update
Set rsExcelOpsResults = Nothing
Set ws = Nothing
Set db = Nothing
End Sub
Like I said, it runs FINE the first time though the loop.
After the first time, is when it throws an error on either one of the two red lines.
I've tried quite a few ways to be more specific (to avoid the _Global), but nothing seems to work for me.
Any Ideas?