G
Gary Harris
I have written some code on VB.NET (and VB6). This code
worked in all other versions of Word, and the same code
is generated in VBA if you record a macro in Word for an
Edit and replace (apart from the "Wordobj" bits)
Now a Com Interop error occurs in .NET. In VB6 the entire
VB6 IDE 9with SP5) completely crashes.
Some sample code in shown below (VB.NET). The
ClearFormatting line causes the error. Just put this
under a button in a .NET Windows form application and
watch it crash! (make a reference in your application to
Microsoft Word 11 Object Library).
Does anybody know of a fix for this?
Thanks in advance,
Gary
Dim WordObj As New
Microsoft.Office.Interop.Word.Application
WordObj.Documents.Add(Template:="Normal.Dot",
NewTemplate:=False)
WordObj.Visible = True
WordObj.Selection.Find.ClearFormatting()
WordObj.Selection.Find.Replacement.ClearFormatting
()
With WordObj.Selection.Find
.Text = "text1"
.Replacement.Text = "text2"
.MatchCase = False
.MatchWholeWord = True
End With
WordObj.Selection.Find.Execute
(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplac
eAll)
worked in all other versions of Word, and the same code
is generated in VBA if you record a macro in Word for an
Edit and replace (apart from the "Wordobj" bits)
Now a Com Interop error occurs in .NET. In VB6 the entire
VB6 IDE 9with SP5) completely crashes.
Some sample code in shown below (VB.NET). The
ClearFormatting line causes the error. Just put this
under a button in a .NET Windows form application and
watch it crash! (make a reference in your application to
Microsoft Word 11 Object Library).
Does anybody know of a fix for this?
Thanks in advance,
Gary
Dim WordObj As New
Microsoft.Office.Interop.Word.Application
WordObj.Documents.Add(Template:="Normal.Dot",
NewTemplate:=False)
WordObj.Visible = True
WordObj.Selection.Find.ClearFormatting()
WordObj.Selection.Find.Replacement.ClearFormatting
()
With WordObj.Selection.Find
.Text = "text1"
.Replacement.Text = "text2"
.MatchCase = False
.MatchWholeWord = True
End With
WordObj.Selection.Find.Execute
(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplac
eAll)