paul.raeburn
PR
- Local time
- Today, 11:21
- Joined
- Apr 29, 2001
- Messages
- 47
I am trying to stop an excel process after working excel through access
2003... it does not seem to matter what I try to do an instace of excel
stays running...
canyone suggest what I maybe doing wrong
here is my code:
>>>code start>>>>
Function transfer_aga_corps_data()
On Error GoTo transfer_aga_corps_data_Err
Dim db As Database
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim DirPath As String
Dim xlsfname As String
Dim xltfname As String
Dim xltTempfname As String
Set db = CurrentDb()
Set xlApp = New Excel.Application
DirPath = "C:\Documents and Settings\PR\My Documents\Downloads\AWSA
Database\"
xltfname = "temp_aga_corps.xls" ' template file
xltTempfname = "UseOnce_temp_aga_corps.xls" ' only used for this
routine
xlsfname = "aga_corps.xls" ' the file that is
used for AWSA/AGA office
xlApp.Visible = False
xlApp.Application.DisplayAlerts = False
xlApp.DisplayAlerts = False
'delete the aga_corps spreadsheet
If Len(Dir(DirPath & xlsfname)) > 0 Then
Kill DirPath & xlsfname
End If
' create a workbook from the template
Set xlBook = Excel.Workbooks.Open(DirPath & xltfname)
' save the template as a workbook
xlBook.SaveAs DirPath & xltTempfname
xlBook.Close
' transfer data to new wookbook
DoCmd.TransferSpreadsheet acExport, 8, "qry_aga_corps", (DirPath &
xltTempfname), True, ""
' run macro in excel
Set xlBook = Excel.Workbooks.Open(DirPath & xltTempfname)
xlApp.Run "create_sheets"
' save workbook the temp workbook as the correct used one
xlBook.SaveAs Filename:=DirPath & xlsfname
xlBook.Close
'delete the UseOnce_temp_aga_corps.xls spreadsheet that is used for this
routine
If Len(Dir(DirPath & xltTempfname)) > 0 Then
Kill DirPath & xltTempfname
End If
'Cleanup
xlApp.Excel.Application.DisplayAlerts = True
xlApp.Excel.Application.Quit
xlApp.Excel.DisplayAlerts = True
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Set db = Nothing
transfer_aga_corps_data_Exit:
Exit Function
transfer_aga_corps_data_Err:
MsgBox Error$
Resume transfer_aga_corps_data_Exit
End Function
<< code end<<
Regards - PR
2003... it does not seem to matter what I try to do an instace of excel
stays running...
canyone suggest what I maybe doing wrong
here is my code:
>>>code start>>>>
Function transfer_aga_corps_data()
On Error GoTo transfer_aga_corps_data_Err
Dim db As Database
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim DirPath As String
Dim xlsfname As String
Dim xltfname As String
Dim xltTempfname As String
Set db = CurrentDb()
Set xlApp = New Excel.Application
DirPath = "C:\Documents and Settings\PR\My Documents\Downloads\AWSA
Database\"
xltfname = "temp_aga_corps.xls" ' template file
xltTempfname = "UseOnce_temp_aga_corps.xls" ' only used for this
routine
xlsfname = "aga_corps.xls" ' the file that is
used for AWSA/AGA office
xlApp.Visible = False
xlApp.Application.DisplayAlerts = False
xlApp.DisplayAlerts = False
'delete the aga_corps spreadsheet
If Len(Dir(DirPath & xlsfname)) > 0 Then
Kill DirPath & xlsfname
End If
' create a workbook from the template
Set xlBook = Excel.Workbooks.Open(DirPath & xltfname)
' save the template as a workbook
xlBook.SaveAs DirPath & xltTempfname
xlBook.Close
' transfer data to new wookbook
DoCmd.TransferSpreadsheet acExport, 8, "qry_aga_corps", (DirPath &
xltTempfname), True, ""
' run macro in excel
Set xlBook = Excel.Workbooks.Open(DirPath & xltTempfname)
xlApp.Run "create_sheets"
' save workbook the temp workbook as the correct used one
xlBook.SaveAs Filename:=DirPath & xlsfname
xlBook.Close
'delete the UseOnce_temp_aga_corps.xls spreadsheet that is used for this
routine
If Len(Dir(DirPath & xltTempfname)) > 0 Then
Kill DirPath & xltTempfname
End If
'Cleanup
xlApp.Excel.Application.DisplayAlerts = True
xlApp.Excel.Application.Quit
xlApp.Excel.DisplayAlerts = True
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Set db = Nothing
transfer_aga_corps_data_Exit:
Exit Function
transfer_aga_corps_data_Err:
MsgBox Error$
Resume transfer_aga_corps_data_Exit
End Function
<< code end<<
Regards - PR