LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
JMB
 
Posts: n/a
Default

Thanks papou! It worked like a charm!

"papou" wrote:

Hello
When you are using the late binding method, it seems that you lose access to
word constants (I have experienced this before).
So I would suggest you try and replace:
.Wrap = wdFindContinue

with
.Wrap = 1

and
.Execute Replace:=wdReplaceAll

with
.Execute Replace:= 2


HTH
Cordially
Pascal

"JMB" a écrit dans le message de news:
...
I've got an Excel macro that opens up a Word document, then uses
Find/Replace
on the Word Document. Upon testing, it seems the code is able to find the
text, but is not replacing it. I don't get any errors when the code
compiles
or runs.

Following is an Excel macro I wrote as a test. When I copy this macro
into
my word document, remark out the lines that don't apply to Word
(references
to WordApp and WordDoc), and replace WordDoc with ThisDocument in the
first
line of my With statement, it runs fine. Any thoughts?

Sub Test()
Const X As String = "%LetterDate%"
Const Y As String = "July 10, 2005"
Dim WordApp as Object
Dim WordDoc as Object

Set WordApp = CreateObject ("Word.Application")
WordApp.Visible = True
WordApp.Documents.Open Filename:="C:\Letters\TSLetter.doc"
Set WordDoc = WordApp.ActiveDocument

With WordDoc.Content.Find
.Text = X
.Replacement.Text = Y
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildCards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
MsgBox .Found
End With

WordDoc.Close SaveChanges:=True
WordApp.Quit
Set WordApp = Nothing

End Sub




 
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
Can Excel Export Data to Word Format? Reddiance Excel Discussion (Misc queries) 2 April 18th 05 06:03 PM
Automation of Excel Data to Word (ref: Galimi answers) Adam Excel Discussion (Misc queries) 3 February 28th 05 04:57 PM
Data Automation from Excel to Word Adam Excel Discussion (Misc queries) 3 February 22nd 05 02:43 PM
How to embed Word document into Excel and retain sizing, formatti. Kent Excel Discussion (Misc queries) 0 February 2nd 05 07:37 PM
Embedded word doc changed to image-need to change back to word. cflores Excel Discussion (Misc queries) 0 January 23rd 05 06:45 AM


All times are GMT +1. The time now is 12:35 AM.

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

About Us

"It's about Microsoft Excel"