![]() |
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 |
All times are GMT +1. The time now is 08:29 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com