Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Earl B
 
Posts: n/a
Default Please help - Missing headers in mail merge

I have a VB.Net tool that is performing a programmatic mail-merge, and one
of my users is putting the merge fields in the header for the document.

For some reason, this isn't working. When I debug the merge process, there
are *no* merge fields listed in the document, but the finished document has
the fields listed.

Does this sound familiar to anybody? Can someone give me a link to an
answer? I'm under the gun on this one, and your help is GREATLY appreciated!


EB
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
 
Posts: n/a
Default Please help - Missing headers in mail merge

1. Can you spell out what you mean by

"When I debug the merge process, there
are *no* merge fields listed in the document, but the finished document has
the fields listed."

There's a starting document called the Mail Merge Main Document, and a
result document (when you merge to a new document, that is). Which contains
what, and how are you finding out?

2. The chances are the the .NET tool is not looking for fields in all the
StoryRanges in the document. Detecting /all/ fields in a document is
non-trivial (in fact, evidence suggests that it may not be possible) but the
following code should catch most of them:

Dim objStory As Range
Dim objField As Field

For Each objStory In ActiveDocument.StoryRanges
For Each objField In objStory.Fields
' do what you want to the field here
Next
' The header/footer ranges can be linked in a way
' that is not revealed by the outer For Each
' so we have to do the following
While Not (objStory.NextStoryRange Is Nothing)
Set objStory = objStory.NextStoryRange
For Each objField In objStory.Fields
' do what you want to the field here
Next
Wend
Next objStory

Set objStory = Nothing
Set objField = Nothing

2. What kind of merge is the user performing? Fields in the header/footer
are likely to behave differently in Catalog/Directory merges than they do in
Letter merges.

Peter Jameieson

"Earl B" wrote in message
. ..
I have a VB.Net tool that is performing a programmatic mail-merge, and one
of my users is putting the merge fields in the header for the document.

For some reason, this isn't working. When I debug the merge process,
there
are *no* merge fields listed in the document, but the finished document
has
the fields listed.

Does this sound familiar to anybody? Can someone give me a link to an
answer? I'm under the gun on this one, and your help is GREATLY
appreciated!


EB



  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Earl B
 
Posts: n/a
Default Please help - Missing headers in mail merge

I am looking at the main document *before* beginning the merge:

Dim docSource As Word.DocumentClass = GetObject(SourceFile)

''' Do the mail merge
merge = docSource.MailMerge
With merge
For Each field As Word.MailMergeField In .Fields
Dim txt As String = field.Code.Text.Trim()
If txt.StartsWith("MERGEFIELD") Then
''' Process the field
End If
Next
end with

I set a breakpoint on the "erge=..." line, then use watches to explore the
document tree. In particular, docSource.merge.fields.count == 0 (which
proves true when I step through the code, it skips over the "for each...")

Thank you for the code snippett - I'll be exploring it today.

EB
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Earl B
 
Posts: n/a
Default Please help - Missing headers in mail merge

That CERTAINLY helped! I still have some content that is in TextFrame
objects (I ~think~ it's in textframe objects), but I can mandate "don't use
those" easily enough.

Thanks!
  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
 
Posts: n/a
Default Please help - Missing headers in mail merge

Good.

You may be able to find more fields by looking in the shapes in the
headers/footers and Text Frames, using e.g.

Dim iStories As Integer
Dim objSection As Section
Dim objHeaderFooter As HeaderFooter
Dim r As Range
Dim s As Shape
For Each objSection in ActiveDocument.Sections
For Each objHeaderFooter in objSection. Headers
For Each s in objHeaderFooter.Shapes
If s.TextFrame.HasText Then
' use s.TextFrame.TextRange to find the fields
End If
Next s
Next objHeaderFooter
For Each objHeaderFooter in objSection.Footers
For Each s in objHeaderFooter.Shapes
If s.TextFrame.HasText Then
' use s.TextFrame.TextRange to find the fields
End If
Next s
Next objHeaderFooter
Next objSection
End Sub
For Each r in ActiveDocument.StoryRanges
If r.StoryType = wdTextFrameStory Then
While Not (r.NextStoryRange Is Nothing)
Set r = r.NextStoryRange
Wend
End If
Next r

Fields in text boxes can be a bit dodgy enyway, although sometimes they may
be the only way to do certain things. Fields in old-style Word frames are
generally a better idea if the user has to use out-of line texts.

Peter Jamieson

"Earl B" wrote in message
. ..
That CERTAINLY helped! I still have some content that is in TextFrame
objects (I ~think~ it's in textframe objects), but I can mandate "don't
use
those" easily enough.

Thanks!





  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Earl B
 
Posts: n/a
Default Please help - Missing headers in mail merge

Thanks - I'll be looking into that the next time these issues come up; for
now it's an in-house tool and I've crossed the "good enough" threshold.

Thanks for the tips!

EB
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
No Mail Merge menu item on Tools menu Gerry Seymour Mailmerge 5 February 2nd 07 06:47 PM
Mail Merge - Parameter prompts twice... TL Mailmerge 6 June 17th 05 02:58 PM
mail merge in word 2003 missing menu Tim Mailmerge 1 June 2nd 05 08:01 AM
Mail Merge Word/OutLook Express Date Missing causes email bounces? Biffo Mailmerge 0 May 19th 05 01:35 PM
Missing lines in mail merge labels Cindy M -WordMVP- Mailmerge 0 November 30th 04 05:25 PM


All times are GMT +1. The time now is 07: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"