Terminating Excel

N

newbie in hell

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("ThisWorkbook").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
 
M

Madhan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top