spebola
Well-known member
I am trying to do a find/replace text in a word document. The code is:
Dim wrdApp As Word._Application
Dim wrdDoc As Word.Document
Dim oRg As Word.Range
Dim mFind As String
Dim mReplText As String
Dim FileName As String
mFind = "<Agreement Date>"
mReplText = Format(mdy, "MMMM dd, yyyy")
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
wrdDoc = wrdApp.Documents.Open(FileName)
wrdDoc.Select()
oRg = wrdDoc.Range
With oRg.Find
.ClearFormatting()
.Forward = True
.Wrap = Word.WdFindWrap.wdFindContinue
.MatchCase = False
.Text = strFind
.Replacement.Text = strReplace
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
When this code is executed I get an error at the .Wrap statement. Error message "Object reference not set to an instance of an object". What step am I leaving out? I am using vb.net 2003 professional and Office XP.
Any comments would be appreciated.
Dim wrdApp As Word._Application
Dim wrdDoc As Word.Document
Dim oRg As Word.Range
Dim mFind As String
Dim mReplText As String
Dim FileName As String
mFind = "<Agreement Date>"
mReplText = Format(mdy, "MMMM dd, yyyy")
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
wrdDoc = wrdApp.Documents.Open(FileName)
wrdDoc.Select()
oRg = wrdDoc.Range
With oRg.Find
.ClearFormatting()
.Forward = True
.Wrap = Word.WdFindWrap.wdFindContinue
.MatchCase = False
.Text = strFind
.Replacement.Text = strReplace
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
When this code is executed I get an error at the .Wrap statement. Error message "Object reference not set to an instance of an object". What step am I leaving out? I am using vb.net 2003 professional and Office XP.
Any comments would be appreciated.