K
kaiser
Hello all,
I am trying to run a macro FROM EXCEL that effects the changes in a
WORD doc. Ie : I want to use the word Find and Replace but call it
from excel...so when I runthe program in excel it makes the changes in
word. here is the code that I gained from the Macro Recorder in
word...it runs fine but doesnt actually change any fields
any advice?
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
.Text = "test"
.Replacement.Text = "Done"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Selection.Find.Execute Replace:=wdReplaceAll
Word.Application.Selection.Find.Execute Replace:=wdReplaceAll
'Word.Application.ActiveDocument.Save
'Word.Application.Quit
End Sub
I am trying to run a macro FROM EXCEL that effects the changes in a
WORD doc. Ie : I want to use the word Find and Replace but call it
from excel...so when I runthe program in excel it makes the changes in
word. here is the code that I gained from the Macro Recorder in
word...it runs fine but doesnt actually change any fields
any advice?
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
.Text = "test"
.Replacement.Text = "Done"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Selection.Find.Execute Replace:=wdReplaceAll
Word.Application.Selection.Find.Execute Replace:=wdReplaceAll
'Word.Application.ActiveDocument.Save
'Word.Application.Quit
End Sub