A
Andrew Cranwell
Hi,
Please redirect me if I am in the wrong group for this question... this is
my first post to this group, so I hope it is clear!
I am working on an automation project in VB.NET and have to interact with
Word 2000 SP-3 to find and replace text within a word document.
Unfortunately, development (not created by me!) occured with Word 2000 SR-1
and on ugrading the references and version to SP-3, some of the code
inexplicably stopped working, I am hoping somebody might be able to help me
here with suggestions of why the failure is occuring.
Debugging had become difficult too - if I try to debug the application,
Visual Studio debugger quits when executing the call to set my Word.Find
object to the value of WordApplication.Selection.Find - this is very
strange, and again any support to solve this would be really appreciated.
The code - previously this worked with SR-1, but with SP-3 now fails:
Private WordApplication As Word.Application
WordApplication = DirectCase(CreateObject("Word.Application"),
Word.Application)
WordDocument = WordApplication.Documents.Open("MyDocFile.Doc")
Dim Search As Word.Find = WordApplication.Selection.Find
' ** FAILURE occurs here... when ClearFormatting called an ActiveX Object
not found error occurs.
' ** Debugger quits if you try to run next line and breaking on
Search.ClearFormatting and trying to watch
' ** the object also causes Debugger to quit - at this point
Word.Application seems to be null...
Search.ClearFormatting()
Search.Text = SubstanceName & "=" & Substance & ControlChars.Cr &
TreatmentName & "=" & Treatment & ControlChars.Cr & SubjectName & "=" &
Subject
Search.Replacement.Text = ""
Search.Forward = True
Search.Wrap = Word.WdFindWrap.wdFindContinue
Search.Format = False
Search.MatchCase = True
Search.MatchWholeWord = False
Search.MatchWildcards = False
Search.MatchSoundsLike = False
Search.MatchAllWordForms = False
Search.Execute()
Many thanks for your help,
Kind Regards,
Andrew
Please redirect me if I am in the wrong group for this question... this is
my first post to this group, so I hope it is clear!
I am working on an automation project in VB.NET and have to interact with
Word 2000 SP-3 to find and replace text within a word document.
Unfortunately, development (not created by me!) occured with Word 2000 SR-1
and on ugrading the references and version to SP-3, some of the code
inexplicably stopped working, I am hoping somebody might be able to help me
here with suggestions of why the failure is occuring.
Debugging had become difficult too - if I try to debug the application,
Visual Studio debugger quits when executing the call to set my Word.Find
object to the value of WordApplication.Selection.Find - this is very
strange, and again any support to solve this would be really appreciated.
The code - previously this worked with SR-1, but with SP-3 now fails:
Private WordApplication As Word.Application
WordApplication = DirectCase(CreateObject("Word.Application"),
Word.Application)
WordDocument = WordApplication.Documents.Open("MyDocFile.Doc")
Dim Search As Word.Find = WordApplication.Selection.Find
' ** FAILURE occurs here... when ClearFormatting called an ActiveX Object
not found error occurs.
' ** Debugger quits if you try to run next line and breaking on
Search.ClearFormatting and trying to watch
' ** the object also causes Debugger to quit - at this point
Word.Application seems to be null...
Search.ClearFormatting()
Search.Text = SubstanceName & "=" & Substance & ControlChars.Cr &
TreatmentName & "=" & Treatment & ControlChars.Cr & SubjectName & "=" &
Subject
Search.Replacement.Text = ""
Search.Forward = True
Search.Wrap = Word.WdFindWrap.wdFindContinue
Search.Format = False
Search.MatchCase = True
Search.MatchWholeWord = False
Search.MatchWildcards = False
Search.MatchSoundsLike = False
Search.MatchAllWordForms = False
Search.Execute()
Many thanks for your help,
Kind Regards,
Andrew