Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Find and replace in Word from Excel

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Find and replace in Word from Excel

On Oct 5, 4:05*pm, gab1972 wrote:
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


I got it...

Sub CreateNewWordDoc()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = GetObject(, "Word.Application")
wrdApp.Visible = True
wrdApp.Activate
Set wrdDoc = wrdApp.Documents.Open("Z:\COMMON FILES\Encroachment
Permits\Permit.Tracker\Testing\testdoc.doc")
With wrdDoc.Range.Find
.Text = "aaaa"
.Replacement.Text = "Insufficient plans."
.Execute Replace:=wdReplaceAll
End With
'wrdApp.Quit ' close the Word application
'Set wrdDoc = Nothing
'Set wrdApp = Nothing
End Sub

....in case anyone was wondering.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Find and replace in Word from Excel

Thanks for the courtesy of posting back with your solution. It could help
someone else.


"gab1972" wrote in message
...
On Oct 5, 4:05 pm, gab1972 wrote:
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


I got it...

Sub CreateNewWordDoc()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = GetObject(, "Word.Application")
wrdApp.Visible = True
wrdApp.Activate
Set wrdDoc = wrdApp.Documents.Open("Z:\COMMON FILES\Encroachment
Permits\Permit.Tracker\Testing\testdoc.doc")
With wrdDoc.Range.Find
.Text = "aaaa"
.Replacement.Text = "Insufficient plans."
.Execute Replace:=wdReplaceAll
End With
'wrdApp.Quit ' close the Word application
'Set wrdDoc = Nothing
'Set wrdApp = Nothing
End Sub

....in case anyone was wondering.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace that contains some word proton Excel Programming 2 August 15th 06 03:39 PM
Find/Replace macro from excel to word Matt[_40_] Excel Programming 4 August 1st 06 03:43 AM
Find/Replace macro from excel into Word Matt[_40_] Excel Programming 0 July 28th 06 04:37 PM
How can I use find and replace to delete a word in Excel? callpaultwt Excel Discussion (Misc queries) 2 December 1st 05 09:11 PM
Ability for Excel to find and replace graphic objects (like Word) Marjan S Excel Worksheet Functions 4 August 26th 05 03:44 AM


All times are GMT +1. The time now is 07:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"