JimfromIndy
06-13-2008, 01:42 PM
From Access 2003, I created a new Excel workbook using the Transferspreadsheet method. It works.
I actually want a blank workbook, so I create a new worksheet, set my active sheet to that new sheet, then try to delete the original sheet. The original sheet WON'T GO AWAY. After I close the workbook, it's still there. No open excel processes, either. What am I doing wrong?
Private Sub btnExportExcel_Click()
Dim ObjExcel As New Excel.Application
'Set ObjExcel = CreateObject("excel.application")
Dim strLocation As String
Dim strFileName As String
strLocation = "c:"
' Put code here to locate the spreadsheet...
strFileName = fOSUserName() & Format(Now(), "yymmddhhss") & ".xls"
Dim x As Excel.Workbook
Dim y As Excel.Worksheet
'DoCmd.OutputTo acOutputTable, "tblHoursBudget", , strLocation & "\" & strFileName
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "tblHoursBudget", strLocation & "\" & strFileName
Set x = ObjExcel.Workbooks.Open(strLocation & "\" & strFileName)
x.Worksheets.Add
x.ActiveSheet.Name = "Project " & ProjectID.Column(1)
Set y = x.ActiveSheet
x.Sheets("tblHoursBudget").Select
x.ActiveSheet.Delete
x.Worksheets("tblHoursBudget").Delete
y.Activate
x.Save
x.Close (True)
Set y = Nothing
Set x = Nothing
Set ObjExcel = Nothing
End Sub
I actually want a blank workbook, so I create a new worksheet, set my active sheet to that new sheet, then try to delete the original sheet. The original sheet WON'T GO AWAY. After I close the workbook, it's still there. No open excel processes, either. What am I doing wrong?
Private Sub btnExportExcel_Click()
Dim ObjExcel As New Excel.Application
'Set ObjExcel = CreateObject("excel.application")
Dim strLocation As String
Dim strFileName As String
strLocation = "c:"
' Put code here to locate the spreadsheet...
strFileName = fOSUserName() & Format(Now(), "yymmddhhss") & ".xls"
Dim x As Excel.Workbook
Dim y As Excel.Worksheet
'DoCmd.OutputTo acOutputTable, "tblHoursBudget", , strLocation & "\" & strFileName
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "tblHoursBudget", strLocation & "\" & strFileName
Set x = ObjExcel.Workbooks.Open(strLocation & "\" & strFileName)
x.Worksheets.Add
x.ActiveSheet.Name = "Project " & ProjectID.Column(1)
Set y = x.ActiveSheet
x.Sheets("tblHoursBudget").Select
x.ActiveSheet.Delete
x.Worksheets("tblHoursBudget").Delete
y.Activate
x.Save
x.Close (True)
Set y = Nothing
Set x = Nothing
Set ObjExcel = Nothing
End Sub