Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / January 2004

Tip: Looking for answers? Try searching our database.

Programmatically expose names of the "Merge fields in document"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lee C. - 08 Jan 2004 22:40 GMT
I see the "Merge fields in document" listed in the document's System
Information | Mail Merge Item Values, but I cannot figure out how to
expose them in code.  I have tried:
  .DataSource.FieldNames.Count 'gives count of total available fields
  .DataSource.DataFields.Count 'also gives count of total available
fields
  .DataSource.MappedDataFields.Count 'not even close to what I want,
but I tried it anyway.

Can someone tell me the name of the DataSource property?

Thanks,
Lee
Peter Jamieson - 09 Jan 2004 08:30 GMT
You could start with something like the following, which inspects /all/
field types. I wouldn't guarantee that it will find them all but it's the
nearest I've ever got.

Sub IterateMergeFields()
Dim r As Range
Dim f As Field
Dim s As Shape
For Each r In ActiveDocument.StoryRanges
 If r.StoryType <> wdTextFrameStory Then
   For Each f In r.Fields
     If f.Type = wdFieldMergeField Then
       ' do whatever you need
     End If
   Next
 End If
Next
For Each s In ActiveDocument.Shapes
 If s.Type = msoTextBox Then
   For Each f In s.TextFrame.TextRange.Fields
     If f.Type = wdFieldMergeField Then
       ' do whatever you need
     End If
   Next
 End If
Next
End Sub

--
Peter Jamieson - Word MVP
Word MVP web site http://www.mvps.org/word

> I see the "Merge fields in document" listed in the document's System
> Information | Mail Merge Item Values, but I cannot figure out how to
[quoted text clipped - 9 lines]
> Thanks,
> Lee
Kathryn Morgand - 09 Jan 2004 15:12 GMT
Thanks.  I was trying another angle, but I'm confused now.  Is that info
that I see in the document's System Information stored in the document's
Compound Document properties?

, Lee

> You could start with something like the following, which inspects /all/
> field types. I wouldn't guarantee that it will find them all but it's the
[quoted text clipped - 41 lines]
> > Thanks,
> > Lee
Peter Jamieson - 09 Jan 2004 18:11 GMT
> Thanks.  I was trying another angle, but I'm confused now.  Is that info
> that I see in the document's System Information stored in the document's
> Compound Document properties?

I don't think it is stored anywhere. As far as I know the System Information
facility is just a program that collects various bits of information about
the Windows environment and the current application and document using a
variety of techniques, presumably including document automation to collect
the info. about the mailmerge fields. But I don't know for sure.

--
Peter Jamieson - Word MVP
Word MVP web site http://www.mvps.org/word

> Thanks.  I was trying another angle, but I'm confused now.  Is that info
> that I see in the document's System Information stored in the document's
[quoted text clipped - 47 lines]
> > > Thanks,
> > > Lee
Kathryn Morgand - 09 Jan 2004 21:20 GMT
Yeah, I've decided that it's not worth trying to figure it out for what I'm
doing.  It just seemed like it should be so simple.

Anyway, I appreciate your insight, Mr. Jamieson.

Thanks again,
Lee

> > Thanks.  I was trying another angle, but I'm confused now.  Is that info
> > that I see in the document's System Information stored in the document's
[quoted text clipped - 62 lines]
> > > > Thanks,
> > > > Lee
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.