A
Arjen van der Hulst
Hi all,
I am trying to implement some Word-automation using the range.find-object
(using VB.net and Word 2000, early binding).
The sample underneath worked well, but after installing an 'after SP3 patch'
for Word ('upgrading' it to build 9.0.8216), it stopped working and now
generates the following error when I try to set the style-part of the
range.find object.
System.NullReferenceException: Object reference not set to an instance of an
object.
at Word.Find.set_Style(Object& prop)
The sample below follows various Microsoft documentation I can find, but
apparently someting has changed, and I can't find out what (though of course
I've already tried various things).
Who can help me?
Thanks in advance,
Arjen van der Hulst
== SAMPLE =================
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRng As Word.Range
Try
oWord = CType(CreateObject("Word.Application"), Word.Application)
oWord.Visible = True
oDoc = oWord.Documents.Add()
oRng = oDoc.Content
With oRng.Find
.Style = Word.WdBuiltinStyle.wdStyleHeading1 '<= here it goes
wrong
.Text = "something"
.Execute()
If .Found Then
MsgBox("Found")
Else
MsgBox("Not Found")
End If
End With
oDoc.Close(False)
oDoc = Nothing
oWord.Quit()
oWord = Nothing
Catch ex As Exception
MsgBox("exception:" & " " & ex.ToString)
Finally
If Not oDoc Is Nothing Then oDoc = Nothing
If Not oWord Is Nothing Then oWord = Nothing
End Try
== END OF SAMPLE ===============
I am trying to implement some Word-automation using the range.find-object
(using VB.net and Word 2000, early binding).
The sample underneath worked well, but after installing an 'after SP3 patch'
for Word ('upgrading' it to build 9.0.8216), it stopped working and now
generates the following error when I try to set the style-part of the
range.find object.
System.NullReferenceException: Object reference not set to an instance of an
object.
at Word.Find.set_Style(Object& prop)
The sample below follows various Microsoft documentation I can find, but
apparently someting has changed, and I can't find out what (though of course
I've already tried various things).
Who can help me?
Thanks in advance,
Arjen van der Hulst
== SAMPLE =================
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRng As Word.Range
Try
oWord = CType(CreateObject("Word.Application"), Word.Application)
oWord.Visible = True
oDoc = oWord.Documents.Add()
oRng = oDoc.Content
With oRng.Find
.Style = Word.WdBuiltinStyle.wdStyleHeading1 '<= here it goes
wrong
.Text = "something"
.Execute()
If .Found Then
MsgBox("Found")
Else
MsgBox("Not Found")
End If
End With
oDoc.Close(False)
oDoc = Nothing
oWord.Quit()
oWord = Nothing
Catch ex As Exception
MsgBox("exception:" & " " & ex.ToString)
Finally
If Not oDoc Is Nothing Then oDoc = Nothing
If Not oWord Is Nothing Then oWord = Nothing
End Try
== END OF SAMPLE ===============