Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Can Excel Export Data to Word Format? | Excel Discussion (Misc queries) | |||
Automation of Excel Data to Word (ref: Galimi answers) | Excel Discussion (Misc queries) | |||
Data Automation from Excel to Word | Excel Discussion (Misc queries) | |||
How to embed Word document into Excel and retain sizing, formatti. | Excel Discussion (Misc queries) | |||
Embedded word doc changed to image-need to change back to word. | Excel Discussion (Misc queries) |