Any idea why the following code crashes?
MSWord 2007 Interface defintions file ("Office12.inc") generated using PBrow.
Sub Speller(UWord As String)
Local oWordApp As Int__Application ' Application Interface.
Local oWordDoc As Int__Document ' Document Interface.
Local oSuggestions As SpellingSuggestions ' Spelling Suggestions collection object.
Local NumWords As Long
' Open a new instance of MSWORD
oWordApp = NewCom $PROGID_Word_Application
If IsTrue IsObject(oWordApp) Then
' Must have at least one document.
If oWordApp.Documents.Count = 0 Then
oWordDoc = oWordApp.Documents.Add
End If
oSuggestions = oWordApp.GetSpellingSuggestions(UWord)
If IsObject(oSuggestions) Then
' CRASH ON NEXT STATEMENT.
NumWords = oSuggestions.Count
If oSuggestions.SpellingErrorType <> %WdSpellingErrorType_wdSpellingCorrect Then
End If
End If
End If
End Sub
Gil.
I may be 100% wrong, but I thought that I remembered Jose mentioning that all of the Office applications (Word, Excel, etc...) operate using a Dispatch interface instead of a direct interface.
Actually, Jose kind of alludes to this in his comments about Excel in another post from today: http://www.jose.it-berater.org/smfforum/index.php?topic=3364.0
And not only that. If you want to be safe, use late binding because M$ has broken all his COM rules with these applications and, if you use early binding, an application compiled using an include file for one version may crash when used with a different version.
The object model of the Office applications has been designed to work mainly with VBA.