Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Terminating Excel
Hi, from which external application are you trying to close the object, how
are you doing it and what is the error you are getting. "newbie in hell" wrote: I opened Excel, created an Excel file, save it, and close it by using automation. But when I try to close the Object (from an external application) I get an Error. Any ideas? ----- before this 8 sheets where created for the workbook---- 'it Creates events appExcel.VBE.MainWindow.Visible = False With appExcel.Workbooks(1).VBProject.VBComponents("This Workbook").CodeModule StartLine = .CreateEventProc("Open", "Workbook") + 1 .InsertLines StartLine, "ActiveWindow.SelectedSheets.PrintPreview" & Chr(13) & "ThisWorkbook.Close" & Chr(13) ' "Application.Workbooks.Close" & Chr(13) & "Application.Quit" & Chr(13) '& "ThisWorkbook.Close" & Chr(13) & "WorkBooks.Exit" & Chr(13) '& "ThisWorkbook.Close" & Chr(13) & "WorkBooks.Exit" & Chr(13) StartLine = .CreateEventProc("BeforeClose", "Workbook") + 1 .InsertLines StartLine, "Application.Workbooks.Close" & Chr(13) & "Application.Quit" & Chr(13) '& "ThisWorkbook.Close" & Chr(13) & "WorkBooks.Exit" & Chr(13) End With appExcel.VBE.MainWindow.Visible = False dummy% = DoEvents() 'VBCodeMod.InsertLines 1, "Sub Auto_open()" & Chr(13) & "ActiveWindow.SelectedSheets.PrintPreview" & Chr(13) & "ThisWorkbook.Close" & Chr(13) & "End Sub" If Trim(Dir(strWorkDir_p & "af1xpt.cht", vbArchive)) < "" Then Kill strWorkDir_p & "af1xpt.cht" strContraseƱa_t = CStr(CDec(Rnd * 1E+15)) appExcel.Workbooks(1).SaveAs "C:\MyFile.xls", xlNormal_t appExcel.Workbooks(1).Save appExcel.Workbooks(1).Close appExcel.VBE.MainWindow.Visible = False appExcel.Workbooks.Close appExcel.quit Set appExcel = Nothing |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
terminating remote links? | Excel Programming | |||
Ensuring Excel start macros complete before terminating | Excel Programming | |||
excel.exe is not terminating from task manager | Excel Programming | |||
Mysteriously terminating code | Excel Programming | |||
Terminating Forms | Excel Programming |