S
ScardyBob
Hello All!
I've run into an annoying problem automating Excel from Access. My
program creates an instance of Excel where users can insert specified
data. Once there finished they can push a button on the Excel worksheet
that imports the data back into Access into the appropriate tables. The
importing process consists of first creating a linked table to the
Excel worksheet and then appending this data to the correct tables.
However, this creates a hidden instance of Excel running in Task
Manager that I have to close manually. I've narrowed down the problem
to the Append method in the following code:
Const ExcelFile As String = "Data"
FileLoc = CurrentProject.Path & "\"
'Create a new Excel Worksheet and make it the visible worksheet
Set xlb = GetObject(FileLoc & ExcelFile & ".xls")
Set xlx = xlb.Parent
Set xlbs = xlx.Workbooks
'Close the open excel workbook
If xlbs.Count = 1 Then
xlb.Close
xlx.Quit
Else
xlb.Close
End If
'Create a new table based on the data located in Excel spreadsheet
Set tdf = db.CreateTableDef(ExcelFile)
strConnect = "Excel 5.0;HDR=YES;IMEX=2;DATABASE=" & FileLoc & ExcelFile
& ".xls"
tdf.Connect = strConnect
tdf.SourceTableName = "Sheet1$"
db.TableDefs.Append tdf <--------- Causes hidden instance of Excel
If I put the xlb.Close and xlx.Quit after the db.TableDefs.Append tdf
then it creates a hidden instance of Excel. Why does it do this?
Thanks in advance!
Mike
I've run into an annoying problem automating Excel from Access. My
program creates an instance of Excel where users can insert specified
data. Once there finished they can push a button on the Excel worksheet
that imports the data back into Access into the appropriate tables. The
importing process consists of first creating a linked table to the
Excel worksheet and then appending this data to the correct tables.
However, this creates a hidden instance of Excel running in Task
Manager that I have to close manually. I've narrowed down the problem
to the Append method in the following code:
Const ExcelFile As String = "Data"
FileLoc = CurrentProject.Path & "\"
'Create a new Excel Worksheet and make it the visible worksheet
Set xlb = GetObject(FileLoc & ExcelFile & ".xls")
Set xlx = xlb.Parent
Set xlbs = xlx.Workbooks
'Close the open excel workbook
If xlbs.Count = 1 Then
xlb.Close
xlx.Quit
Else
xlb.Close
End If
'Create a new table based on the data located in Excel spreadsheet
Set tdf = db.CreateTableDef(ExcelFile)
strConnect = "Excel 5.0;HDR=YES;IMEX=2;DATABASE=" & FileLoc & ExcelFile
& ".xls"
tdf.Connect = strConnect
tdf.SourceTableName = "Sheet1$"
db.TableDefs.Append tdf <--------- Causes hidden instance of Excel
If I put the xlb.Close and xlx.Quit after the db.TableDefs.Append tdf
then it creates a hidden instance of Excel. Why does it do this?
Thanks in advance!
Mike