Set objXL = WScript.CreateObject ("Excel.Application")
This command retrieves an object reference to the Excel Application object.
Because we omit here a version number, any installed Excel version
(95/97/2000) will be invoked. If you like to invoke Excel 97 for instance,
you must add also the internal version number as:
Set objXL = WScript.CreateObject ("Excel.Application.8")
Afterwards you can use the object variable objXL to access the Application
object and its sub-objects from the script. The following sequence sets the
properties of the Excel window:
objXL.WindowState = vbNormal ' Normal
objXL.Height = 300 ' height
objXL.Width = 400 ' width
objXL.Left = 40 ' X-Position
objXL.Top = 20 ' Y-Position
objXL.Visible = true ' show window
Then you may load a file (either an XLS file or a file with another format).
Below I try to load a Comma Separated Value (CSV) file.
Set objWb = objXl.WorkBooks.Open(file)
The variable file must contain the whole path and the name of the import file.
Because Excel loads Workbooks, we must access also the Open method provided
by the WorkBooks object. According to the Excel object model, this object is
a sub-object of the Application object. Therefore we can use objXL.WorkBooks
to address the WorkBooks object.
After loading the file, we shall set the workbook as the current workbook.
This may be done using the following command:
Set objWb = objXL.ActiveWorkBook.WorkSheets("Test")
objWb.Activate ' not absolutely necessary (for CSV)
I assumed that the worksheet was named "Test" (which is the case, if we
import a file Test.csv). Otherwise you must insert the name of your
worksheet. The Activate method causes that the worksheet will be visible
in the foreground. You can use the Cells object to access cells within a
workbook. The following lines show how to read a few cells:
WScript.Echo CStr(objWb.Cells(1, 1).Value) & vbTab & _
CStr(objWb.Cells(1, 2).Value)
To print out the content of the current worksheet, you must use the PrintOut
method using the following command:
objXl.ActiveSheet.PrintOut
objXl.Quit
-----------------------------------------------------------------------------