Microsoft Office Tutorials and References
In Depth Information
Table 21-2. Excel Objects and Their Functions
Top-Level Office Object
Class Name
Application object
CreateObject(“Excel.Application”)
Workbook object
CreateObject(“Excel.Sheet”)
Chart object
CreateObject(“Excel.Chart”)
The following procedure was created in Word 2003. A reference was included to reference the
Excel Object Library. To execute this procedure, you must add the Excel reference, enter the
procedure into Word, and then create a new workbook in the root directory of your C: drive
named NewExcelWbk.xls .
Sub OpenWriteExcelWbkContents()
Dim xlApp As Excel.Application
Dim xlWbk As Excel.Workbook
Dim tString As String, r As Long
Documents.Add
Set xlApp = CreateObject("Excel.Application”)
Set xlWbk = Excel.Workbooks.Open("C:\NewExcelWbk.xls”)
r=1
With xlWbk.Worksheets(1)
While .Cells(r, 1).Formula <> ""
tString = Cells(r, 1).Formula
With ActiveDocument.Content
.InsertAfter "Contents of file: " & xlWbk.Name
.InsertParagraphAfter
.InsertParagraphAfter
.InsertAfter tString
.InsertParagraphAfter
End With
r=r+1
Wend
End With
xlWbk.Close
xlApp.Quit
Set xlWbk = Nothing
Set xlApp = Nothing
End Sub
The previous example created a basic Excel workbook. Now that you can create a basic
workbook, you can copy data and a chart into a Word document. One such workbook is shown in
Figure 21-5.
Search JabSto ::




Custom Search