Searching this group i found interesting solutions and couple of problems.
I need to search from VB.net, text in Word and replace that text with replacement text. I need to replace 500+ words!
-VB.net 2005 express
-word 2003
-PIA reference added
Till now the only problem is "ActiveDocument" not declared, but when I play with it, I gort more errors...VB Code:
Imports Word = Microsoft.Office.Interop.Word Public Function DoFindReplace() Dim oWord As New Word.Application Dim oDoc As Word.Document Dim sFind As String Dim sReplace As String oDoc = oWord.ActiveDocument.Content Dim rngRange As Word.Range = ActiveDocument.Range 'Problem: Not Declared With rngRange.Find .ClearFormatting() .Replacement.ClearFormatting() .Text = sFind .Replacement.Text = sReplace .Forward = True .Wrap = Word.WdFindWrap.wdFindContinue .Format = False .MatchCase = True .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute(Replace:=Word.WdReplace.wdReplaceAll) End With End Function Private Sub subsubTran_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles subsubTran.Click Dim oWord As New Word.Application Dim oDoc As Word.Document Dim path As String = Me.TextBox1.Text oWord.Visible = False oDoc = oWord.Documents.Open(path) Call DoFindReplace("System", "Computer", ActiveDocument.Range)'Problem: Not Declared Call DoFindReplace("test", "tempo", ActiveDocument.Range)'Problem: Not Declared Call DoFindReplace("car", "bus", ActiveDocument.Range)'Problem: Not Declared 'etc. etc. oDoc.SaveAs(path) oDoc.Close() oDoc = Nothing oWord.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone oWord.Quit() oWord = Nothing End Sub
Any help appriciated. And yes, this is my firstencounter with VB.net or similar. Sorry for bad english.
Zeljko




encounter with VB.net or similar. Sorry for bad english.
Reply With Quote