EDN Admin
Well-known member
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports Word = Microsoft.Office.Interop.Word
<span style="color:Blue; Dim str_FullName = <span style="color:#A31515; "Microsoft Corporation"
<span style="color:Blue; Dim oWordApp <span style="color:Blue; As <span style="color:Blue; New Word.Application
oWordApp.Visible = <span style="color:Blue; true
<span style="color:Blue; Dim oDoc <span style="color:Blue; As Word.Document = oWordApp.Documents.Open(wordFilePath)
oDoc = oWordApp.ActiveDocument
objDoc.Content.Find.Execute(FindText:=<span style="color:#A31515; "{COMPANY FULLNAME}", ReplaceWith:=str_FullName, Replace:=Word.WdReplace.wdReplaceAll)
<span style="color:Blue; While objDoc.Content.Find.Execute(FindText:=<span style="color:#A31515; " ", Wrap:=Word.WdFindWrap.wdFindContinue)
objDoc.Content.Find.Execute(FindText:=<span style="color:#A31515; " ", ReplaceWith:=<span style="color:#A31515; " ", Replace:=Word.WdReplace.wdReplaceAll, Wrap:=Word.WdFindWrap.wdFindContinue)
<span style="color:Blue; End <span style="color:Blue; While
objDoc.Save()
objDoc.Close()
objDoc = <span style="color:Blue; Nothing
objWordApp.Quit()
objWordApp = <span style="color:Blue; Nothing
[/code]
Im not sure why the code wont work...<br/>
It opens the document without problems, it just wont find and replace the text. No, I did NOT typo the text its supposed to be finding. I copied and pasted it straight out of the word document.<br/>
<br/>
Any help is appreciated.<hr class="sig -Nothing to see. Move along.
View the full article
<span style="color:Blue; Imports Word = Microsoft.Office.Interop.Word
<span style="color:Blue; Dim str_FullName = <span style="color:#A31515; "Microsoft Corporation"
<span style="color:Blue; Dim oWordApp <span style="color:Blue; As <span style="color:Blue; New Word.Application
oWordApp.Visible = <span style="color:Blue; true
<span style="color:Blue; Dim oDoc <span style="color:Blue; As Word.Document = oWordApp.Documents.Open(wordFilePath)
oDoc = oWordApp.ActiveDocument
objDoc.Content.Find.Execute(FindText:=<span style="color:#A31515; "{COMPANY FULLNAME}", ReplaceWith:=str_FullName, Replace:=Word.WdReplace.wdReplaceAll)
<span style="color:Blue; While objDoc.Content.Find.Execute(FindText:=<span style="color:#A31515; " ", Wrap:=Word.WdFindWrap.wdFindContinue)
objDoc.Content.Find.Execute(FindText:=<span style="color:#A31515; " ", ReplaceWith:=<span style="color:#A31515; " ", Replace:=Word.WdReplace.wdReplaceAll, Wrap:=Word.WdFindWrap.wdFindContinue)
<span style="color:Blue; End <span style="color:Blue; While
objDoc.Save()
objDoc.Close()
objDoc = <span style="color:Blue; Nothing
objWordApp.Quit()
objWordApp = <span style="color:Blue; Nothing
[/code]
Im not sure why the code wont work...<br/>
It opens the document without problems, it just wont find and replace the text. No, I did NOT typo the text its supposed to be finding. I copied and pasted it straight out of the word document.<br/>
<br/>
Any help is appreciated.<hr class="sig -Nothing to see. Move along.
View the full article