blacktusk
06-18-2009, 06:56 PM
I have an Excel Application that is being automatically spawned from another Application. The Excel is running a report lookup and printout called from Sub Workbook_Open()
I dont believe that the details of the report are significant. Essentially if the workbook is opened with the /print option then the Printout occurs automatically and then closes the workbook. This all works fine, however the Excel application window will not close.
Private Sub Workbook_Open()
Dim CmdRaw As Long
Dim CmdLine As String
Dim doPrint As Long
Dim xlApp As Excel.Application
Set xlApp = Me.Application
CmdRaw = GetCommandLine
CmdLine = CmdToSTr(CmdRaw)
'MsgBox CmdLine
doPrint = InStr(CmdLine, "print")
'MsgBox "starting"
If doPrint > 0 Then 'Report Date is yesterday
xlApp.Sheets("report").Cells(1, 4).Value = Format(DateAdd("d", -1, Date), "yyyy-mm-dd")
Else
xlApp.Sheets("report").Cells(1, 4).Value = Format(Date, "yyyy-mm-dd")
End If
'ActiveSheet.Cells(2, 4).Value = Format(Date, "yyyy-mm-dd")
RunReport1 "A7"
If doPrint > 0 Then
xlApp.Sheets("report").PrintOut
'xlApp.ScreenUpdating = False
xlApp.DisplayAlerts = False
For Each Workbook In xlApp.Workbooks
Workbook.Close (False)
Next
xlApp.Quit
Set xlApp = Nothing
End If
End Sub
I dont believe that the details of the report are significant. Essentially if the workbook is opened with the /print option then the Printout occurs automatically and then closes the workbook. This all works fine, however the Excel application window will not close.
Private Sub Workbook_Open()
Dim CmdRaw As Long
Dim CmdLine As String
Dim doPrint As Long
Dim xlApp As Excel.Application
Set xlApp = Me.Application
CmdRaw = GetCommandLine
CmdLine = CmdToSTr(CmdRaw)
'MsgBox CmdLine
doPrint = InStr(CmdLine, "print")
'MsgBox "starting"
If doPrint > 0 Then 'Report Date is yesterday
xlApp.Sheets("report").Cells(1, 4).Value = Format(DateAdd("d", -1, Date), "yyyy-mm-dd")
Else
xlApp.Sheets("report").Cells(1, 4).Value = Format(Date, "yyyy-mm-dd")
End If
'ActiveSheet.Cells(2, 4).Value = Format(Date, "yyyy-mm-dd")
RunReport1 "A7"
If doPrint > 0 Then
xlApp.Sheets("report").PrintOut
'xlApp.ScreenUpdating = False
xlApp.DisplayAlerts = False
For Each Workbook In xlApp.Workbooks
Workbook.Close (False)
Next
xlApp.Quit
Set xlApp = Nothing
End If
End Sub