Microsoft Office Tutorials and References
In Depth Information
Set wrdApp = CreateObject("Word.Application”)
Set wrdDoc = GetObject("C:\GSC\Correspondence\Spring Promotion.doc”)
With wrdDoc
For i = 1 To .Paragraphs.Count
Set tRange = .Range(Start:=.Paragraphs(i).Range.Start, _
tString = tRange.Text
tString = Left(tString, Len(tString) - 1)
ActiveSheet.Range("A” & r).Formula = tString
Next i
End With
With Range("A1”)
.Formula = "File Contents of: " & wrdDoc.Name
.Font.Italic = True
.Font.Size = 18
End With
Set wrdDoc = Nothing
Set wrdApp = Nothing
ActiveWorkbook.Saved = True
End Sub
Inside Out
GetObject vs. CreateObject
The GetObject and the CreateObject functions both return references to an object, so how
do you choose which one to use?
The CreateObject function is used to create a new instance of the application. Use this func­
tion if the application you need to reference is not currently open. If an instance is already
running, a second instance of the application will be initiated. Consider the following exam­
ple. The Garden Supply Company has an Excel Workbook that copies data into a Microsoft
Word document for the monthly sales reports. To create a new instance of Microsoft Word,
you should use the following code:
Set xlApp = CreateObject("Word.Application”)
The GetObject function is used with an application that is already running or to start an
application with a file already loaded. The following example starts Excel and opens
Set XLBook = GetObject("C:\Myfile.xls”)
The object returned in XLBook is a reference to the Workbook object.
Search JabSto ::

Custom Search