The ActiveX Script editor gets displayed and it is
initially empty.
Chapter 18
[ 267 ]
6. Type in the text into the ActiveX Script text Editor as shown in the
following screenshot.
The following is the code with comments:
Function Main ()
'This next statement calls the sub procedure
Call spellErrors
Main = DTSTaskExecResult_Success
end Function
Sub spellErrors ()
'Create a word automation object with the next stataement
Set WordApp=CreateObject ("Word.Application","Hodentek")
'Display the programmatic name of the application object
MsgBox (WordApp.name)
'Add a document to the Documents collection
Package with an ActiveX Script Task
[ 268 ]
WordApp.Documents.Add
'Establish a range in the active document
Set extent = WordApp.ActiveDocument.Range
'Insert a short sentence with errors using the insertAfter method
extent.InsertAfter "The hous ws on firedx."
'Use SpellCollection to collect errors in the sentence
Set SpellCollection = extent.SpellingErrors
'Display the number of errors in a message box.
MsgBox (SpellCollection.Count)
'Display the word document
WordApp.Visible = true
End sub
7. Click on the point indicated by 2 and type in Main.
This is the entry point for the script and the code begins to execute from
this point.
8. Build the project and execute the ActiveX Script Task??”Count
Spelling Errors.
The first message box shows Microsoft Word as the name of the application. The
second window shows the number 3, 3 being the number of errors in this short
sentence.
Pages:
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188