CloseExcelCom
File management function.
The CloseExcelCom function closes the background Excel instance loaded by WriteExcel or ReadExcel.
Usage
If you need to automate directly the Excel interface after having used WriteExcel/ReadExcel functions, use CloseExcelCom function before using the Shell function to launch Excel.
Syntax
CloseExcelCom()
or
ret=CloseExcelCom()Parameters
None
Return value
Ret, numeric return code. When the background Excel application has been closed successfully, the function returns 0, otherwise the function returns -1.
Example
This script example captures the market indices on yahoo finances, writes them into Excel, opens the resulting Excel file and prints it.
'The 3 arrays for capturing the columns
Dim tabcell_2$(100)
Dim tabcell_1$(100)
Dim tabcell_0$(100)StartBrowser("IE", "http://finance.yahoo.com")
'Capture the finances data and write them in c:\finance.xls
UsePage("Yahoo! Finance - Get stock quotes, market news, mortgage rates & currency info.")
ret = CaptureTableHTML("TABLE[CONTENT='Symbol']", "R1C1:R7C1", tabcell_0$())
ret = WriteExcel("c:\finance.xls", "Sheet1!A1:A7", tabcell_0$())
ret = CaptureTableHTML("TABLE[CONTENT='Symbol']", "R1C2:R7C2", tabcell_1$())
ret = WriteExcel("c:\finance.xls", "Sheet1!B1:B7", tabcell_1$())
ret = CaptureTableHTML("TABLE[CONTENT='Symbol']", "R1C3:R7C3", tabcell_2$())
ret = WriteExcel("c:\finance.xls", "Sheet1!C1:C7", tabcell_2$())
'As Excel is launched after a WriteExcel, CloseExcelCom line is mandatory.
CloseExcelCom()
Shell(Chr$(34)+"C:\Program Files\Microsoft Office\Office\EXCEL.EXE"+Chr$(34)+" c:\finance.xls",1)
'Print the Excel file - always use the keyboard shortcuts in Excel automation
UseWindow("EXCEL.EXE|MsoCommandBar|Worksheet Menu Bar")
SendKeys("<Alt F>")
pause 10 ticks
SendKeys("P")
UseWindow("EXCEL.EXE|bosa_sdm_XL9|Print",1)
SendKeys("<Enter>")