LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Replacing Word text with Excel data problem


I have a macro to open a word document from Excel 2003. I then need
replace text in the document with data from cells in a spreadsheet.

I open a version of word and then the spreadsheet as follows:

Sub ReplaceText()
Dim wdApp As Word.Application
dim ReplaceText as String

ReplaceText= Range("C2")

Set wdApp = CreateObject("word.application")
wdApp.Documents.Open("P:\WordDocument.doc").Applic ation.Visible = True

With wdApp
..Visible = True
..WindowState = 1
With Selection.Find
..Text= "OAKNo"
..Replacement.Text = ReplaceText
..Forward = True
..Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
End With
End Sub

This opens the word document but will not replace the text. However, I
can, for instance, add text to the document using:
Selection .TypeText Text:="text".
Also the replace code will run from within a subroutine in the word
document.
Any thoughts on why the replace code will not work, or another way to
do this would be very gratefully received.
Paul


--
PaulC
------------------------------------------------------------------------
PaulC's Profile: http://www.excelforum.com/member.php...fo&userid=7563
View this thread: http://www.excelforum.com/showthread...hreadid=514389

 
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
Add text to cell without replacing current data mubzee Excel Discussion (Misc queries) 2 October 11th 09 05:43 AM
Extracting and replacing the first word in a String of text RAYCV Excel Worksheet Functions 5 August 21st 09 01:15 PM
Merge Data problem from Excel to Word AndyC812 Excel Discussion (Misc queries) 2 June 12th 08 02:43 AM
Problem inserting Excel data into Word Philamental Excel Discussion (Misc queries) 6 February 14th 06 11:47 AM
Replacing instances in word with data from exel Jere[_2_] Excel Programming 0 May 7th 04 12:31 PM


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

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"