G
gab1972
From Excel, I need to open a Word document, find "aaaa" in the Word
document, and then replace "aaaa" with the contents in A1 in Excel.
The code I have doesn't like .Selection.Find
Please help. Thanks in advance.
Sub FindReplace()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("Z:\COMMON FILES\Encroachment
Permits\Permit.Tracker\Testing\testdoc.doc")
With wrdDoc
With .Selection.Find
.Text = "aaaa"
.Replacement.Text = Cells("A1")
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
If Dir("Z:\COMMON FILES\Encroachment Permits\Permit.Tracker
\Testing\MyNewWordDoc.doc") <> "" Then
Kill "Z:\COMMON FILES\Encroachment Permits\Permit.Tracker
\Testing\MyNewWordDoc.doc"
End If
End With
End Sub
document, and then replace "aaaa" with the contents in A1 in Excel.
The code I have doesn't like .Selection.Find
Please help. Thanks in advance.
Sub FindReplace()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("Z:\COMMON FILES\Encroachment
Permits\Permit.Tracker\Testing\testdoc.doc")
With wrdDoc
With .Selection.Find
.Text = "aaaa"
.Replacement.Text = Cells("A1")
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
If Dir("Z:\COMMON FILES\Encroachment Permits\Permit.Tracker
\Testing\MyNewWordDoc.doc") <> "" Then
Kill "Z:\COMMON FILES\Encroachment Permits\Permit.Tracker
\Testing\MyNewWordDoc.doc"
End If
End With
End Sub