PC Review


Reply
Thread Tools Rate Thread

Dynamic Data from Excel to Word

 
 
=?Utf-8?B?YW5hbWFyaWUzMA==?=
Guest
Posts: n/a
 
      10th Aug 2007
I got a Word Document template with some keys phrases to be replaced by the
content (for example, document numbers, etc.) of specific cells located on a
Excel workbook. I want that my code search in the Word document for specifics
phrases and replace that with the text that my specific cells had. How can I
do that? Ideas will be appreciated.
 
Reply With Quote
 
 
 
 
Dave D-C
Guest
Posts: n/a
 
      12th Aug 2007
' This is a start (works with Office97) - mainly for my benefit.
' Hope this helps you. Thanks for the post.

Option Explicit

Sub sub1()
' This assumes that Word is running and z1.doc is open and active.
' Word could be "created" if not running.
' z1.doc could be opened if not open.
' z1.doc could be activated if not active.
Dim zObj As Object, sFind$, sReplace$
sFind = Cells(1, 1)
sReplace = Cells(1, 2)
On Error GoTo err1
Set zObj = GetObject(, "Word.Application")
On Error GoTo err2
If Not zObj.Windows("z1.doc").Active Then
MsgBox "z1.doc not active": End
End If
On Error GoTo 0
With zObj ' now we're talking to Word
.Selection.Find.ClearFormatting
.Selection.Find.Replacement.ClearFormatting
.Selection.Find.Text = sFind
.Selection.Find.Replacement.Text = sReplace
.Selection.Find.Forward = True
.Selection.Find.Wrap = 1 ' wdFindContinue
.Selection.Find.Format = False
.Selection.Find.MatchCase = False
.Selection.Find.MatchWholeWord = False
.Selection.Find.MatchWildcards = False
.Selection.Find.MatchSoundsLike = False
.Selection.Find.MatchAllWordForms = False
.Selection.Find.Execute Replace:=2 ' wdReplaceAll
End With
Exit Sub
err1:
MsgBox "Word not active": End
err2:
MsgBox "z1.doc not open": End
End Sub

>anamarie30 <(E-Mail Removed)> wrote:
>I got a Word Document template with some keys phrases to be replaced by the
>content (for example, document numbers, etc.) of specific cells located on a
>Excel workbook. I want that my code search in the Word document for specifics
>phrases and replace that with the text that my specific cells had. How can I
>do that? Ideas will be appreciated.



----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
 
Reply With Quote
 
=?Utf-8?B?YW5hbWFyaWUzMA==?=
Guest
Posts: n/a
 
      14th Aug 2007
Thanks for your help, Dave D-C!

"Dave D-C" wrote:

> ' This is a start (works with Office97) - mainly for my benefit.
> ' Hope this helps you. Thanks for the post.
>
> Option Explicit
>
> Sub sub1()
> ' This assumes that Word is running and z1.doc is open and active.
> ' Word could be "created" if not running.
> ' z1.doc could be opened if not open.
> ' z1.doc could be activated if not active.
> Dim zObj As Object, sFind$, sReplace$
> sFind = Cells(1, 1)
> sReplace = Cells(1, 2)
> On Error GoTo err1
> Set zObj = GetObject(, "Word.Application")
> On Error GoTo err2
> If Not zObj.Windows("z1.doc").Active Then
> MsgBox "z1.doc not active": End
> End If
> On Error GoTo 0
> With zObj ' now we're talking to Word
> .Selection.Find.ClearFormatting
> .Selection.Find.Replacement.ClearFormatting
> .Selection.Find.Text = sFind
> .Selection.Find.Replacement.Text = sReplace
> .Selection.Find.Forward = True
> .Selection.Find.Wrap = 1 ' wdFindContinue
> .Selection.Find.Format = False
> .Selection.Find.MatchCase = False
> .Selection.Find.MatchWholeWord = False
> .Selection.Find.MatchWildcards = False
> .Selection.Find.MatchSoundsLike = False
> .Selection.Find.MatchAllWordForms = False
> .Selection.Find.Execute Replace:=2 ' wdReplaceAll
> End With
> Exit Sub
> err1:
> MsgBox "Word not active": End
> err2:
> MsgBox "z1.doc not open": End
> End Sub
>
> >anamarie30 <(E-Mail Removed)> wrote:
> >I got a Word Document template with some keys phrases to be replaced by the
> >content (for example, document numbers, etc.) of specific cells located on a
> >Excel workbook. I want that my code search in the Word document for specifics
> >phrases and replace that with the text that my specific cells had. How can I
> >do that? Ideas will be appreciated.

>
>
> ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
> ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
a Dynamic Excel Worksheet in Word Duane Microsoft Word New Users 1 24th Jul 2009 10:19 PM
Dynamic reference of word doc in excel tims Microsoft Excel Misc 1 24th Jan 2009 12:36 PM
how to create an dynamic data table/chart in word using vba =?Utf-8?B?TWFyaw==?= Microsoft Powerpoint 0 2nd Nov 2004 02:56 PM
how to create an dynamic data table/chart in word =?Utf-8?B?TWFyaw==?= Microsoft Word Document Management 0 2nd Nov 2004 02:18 PM
Dynamic Excel Charts in Word Grady Microsoft Excel Misc 0 8th Oct 2003 11:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:17 PM.