Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have vbscripts that open a workbook, run it's Sub Main
procedure, then close the workbook. Each workbook is using ADO to get data from a database. The basic code for the script looks like this: Set xl = CreateObject("Excel.Application") Set CurrentBook = xl.Workbooks.Open ("C:\MyPath\MyWorkbook.xls") xl.Run "Main" CurrentBook.Save CurrentBook.Close xl.Quit Set CurrentBook = Nothing Set xl = Nothing This works fine. However, two of the workbooks stay open in memory after the Sub Main has run. Upon investigation, these are the only two workbooks in the bunch that use the ADO Parameter object. That code looks something like: 'Where cn is my ADO Connection cn.Open "Driver={Microsoft Access Driver (*.mdb));Dbq=C:\DatabasePath\MyDatabase.mdb;" 'Where cm is my ADO cmWith cm With cm .ActiveConnection = cn .CommandText = "qryMyAccessQuery" .CommandType = adCmdStoredProc Set pm1 = cm.CreateParameter ("DateField",adDate,adParamInput) .Parameters.Append pm1 pm1.Value = #4/1/2004# Set pm2 = cm.CreateParameter ("DateField",adDate,adParamInput) .Parameters.Append pm2 pm2.Value = #4/30/2004# End With 'Where rs is my ADO Recordset rs.Open cm ActiveSheet.Range("A2").CopyFromRecordSet rs rs.Close cn.Close Set cn = Nothing Set rs = Nothing Set pm1 = Nothing Set pm2 = Nothing If I open the workbook manually and run the code it works fine. If I run the script, it opens the workbook and runs the code, but does not close the workbook. tod |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Tod" wrote in message ...
I have vbscripts that open a workbook, run it's Sub Main procedure, then close the workbook. Each workbook is using ADO to get data from a database. The basic code for the script looks like this: Set xl = CreateObject("Excel.Application") Set CurrentBook = xl.Workbooks.Open ("C:\MyPath\MyWorkbook.xls") xl.Run "Main" CurrentBook.Save CurrentBook.Close xl.Quit Set CurrentBook = Nothing Set xl = Nothing This works fine. However, two of the workbooks stay open in memory after the Sub Main has run. Are you allowing enough time for xl.Run "Main" to complete before executing CurrentBook.Save CurrentBook.Close ? -- |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Insert Object Problem | Excel Discussion (Misc queries) | |||
insert object problem | Excel Discussion (Misc queries) | |||
How to choose if I use a parameter or not in a parameter query | Excel Discussion (Misc queries) | |||
Problem with named range as VBA macro parameter | Excel Programming | |||
Object variable problem | Excel Programming |