Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
mocha99 mocha99 is offline
external usenet poster
 
Posts: 19
Default Word2007-Excel2007 data merge

Hi all,

in my Word document i have some placeholders in the footnotes like [22 .

I have an Excel spreadsheet were in column A I have the same placeholder
of the Word document and in column B the associated value like in

A B
[22 cow

Is there a way to automatically substitute the string [22 in the Word
doc with the string cow from Excel? I have tried with mailmerge but
could not figure out how to do it.

Thanks
  #2   Report Post  
Posted to microsoft.public.word.newusers
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Word2007-Excel2007 data merge

The following code in a Word macro should do what you want if you follow the
Requirements below the code:

Dim i As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
With ActiveDocument
For i = 1 To .Footnotes.Count
If InStr(.Footnotes(i).Range.Text, "[") 0 Then
' Open the database
Set db = OpenDatabase("C:\Test\Book1.xls", False, False, "Excel
8.0")
' Retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM `myDatabase`")
'Loop through all the records in the table until the end-of-file
marker is reached
Do While Not rs.EOF
If rs.Fields(1) = .Footnotes(i).Range.Text Then
.Footnotes(i).Range.Text = rs.Fields(2)
End If
rs.MoveNext
Loop
' Cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End If
Next i
End With

Requirements:

First, you need to set a reference in your project to the "Microsoft DAO
3.51 (or 3.6) Object Library". This is done by selecting References from
the Tools menu in the Visual Basic Editor.

If you are needing to retrieve the data from an Excel 2007 spreadsheet,
instead of the reference being to the "Microsoft DAO 3.51 (or 3.6) Object
Library, it needs to be to the Microsoft Office 12.0 Access database engine
Object Library and replace the following line of code in the above macro:

Set db = OpenDatabase("C:\Test\Book1.xls", False, False, "Excel
8.0")

with:

Set db = OpenDatabase("C:\Test\Book1.xls", False, False, "Excel
12.0")

In the above lines of code, you will need to replace the

C:\Test\Book1.xls

with the path and name of your Excel Spreadsheet.

In that Excel Spreadsheet, you will need to have assigned the name

myDatabase

to the cells in Column A and B that contain the placeholders and the text
associated with them.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"mocha99" wrote in message
...
Hi all,

in my Word document i have some placeholders in the footnotes like [22 .

I have an Excel spreadsheet were in column A I have the same placeholder
of the Word document and in column B the associated value like in

A B
[22 cow

Is there a way to automatically substitute the string [22 in the Word doc
with the string cow from Excel? I have tried with mailmerge but could not
figure out how to do it.

Thanks


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does a Word2003 data source open as Read-Only in Word2007? Kristi in Oregon Mailmerge 4 May 28th 08 03:58 AM
Unable to Mail Merge in Word2007-Outlook2007 After Office2007 SP1 Mills Architect Mailmerge 1 December 15th 07 06:23 PM
Mailmerge in word 2007 of excel2007 file 256 columns (in fact 400 Briza Mailmerge 3 November 5th 07 08:13 AM
DotNet Data Table as Mail Merge Data Source goraya Mailmerge 1 July 7th 05 09:51 AM
data in mail merge letter being cut off - data source field size? tgone Mailmerge 1 May 20th 05 02:10 PM


All times are GMT +1. The time now is 09:54 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"