K
kaiser
Hello all,
I am trying to search a word doc and change all words "test" with
"done", all from an excel macro.
I know there are shorter ways of eliminating a lot of text in my macro
(with , end with etc) but for my learning purposes now I would like to
avoid them.
Here is my code THAT DOESNT work.....any comments on what I am doing
wrong pls -the error message is "Method or data member cannot be found
when I try run it on the ".Replacement.Text = "Done"" line
Sub AddData()
Dim StringToSearch As String
Dim counter As Long
'StringToSearch = "test"
'Word.Application.WindowState = wdWindowStateMaximize
Word.Application.Documents.Open ("c:\Temp\destination.doc")
'Word.Application.ActiveDocument.Range.InsertAfter
StringToSearch
Word.Application.ActiveDocument.Range.Find.Replacement.ClearFormatting
With Word.Application.ActiveDocument.Range.Find.Replacement
.Text = "test"
.Replacement.Text = "Done"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Word.Application.ActiveDocument.Range.Find.Execute
Replace:=wdReplaceAll
'Word.Application.ActiveDocument.Save
'Word.Application.Quit
End Sub
I am trying to search a word doc and change all words "test" with
"done", all from an excel macro.
I know there are shorter ways of eliminating a lot of text in my macro
(with , end with etc) but for my learning purposes now I would like to
avoid them.
Here is my code THAT DOESNT work.....any comments on what I am doing
wrong pls -the error message is "Method or data member cannot be found
when I try run it on the ".Replacement.Text = "Done"" line
Sub AddData()
Dim StringToSearch As String
Dim counter As Long
'StringToSearch = "test"
'Word.Application.WindowState = wdWindowStateMaximize
Word.Application.Documents.Open ("c:\Temp\destination.doc")
'Word.Application.ActiveDocument.Range.InsertAfter
StringToSearch
Word.Application.ActiveDocument.Range.Find.Replacement.ClearFormatting
With Word.Application.ActiveDocument.Range.Find.Replacement
.Text = "test"
.Replacement.Text = "Done"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Word.Application.ActiveDocument.Range.Find.Execute
Replace:=wdReplaceAll
'Word.Application.ActiveDocument.Save
'Word.Application.Quit
End Sub