Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
PromisedOyster PromisedOyster is offline
external usenet poster
 
Posts: 4
Default Is there a workaround for a bug with automation related to StoryRanges

The following code iterates through all merge fields:

foreach (Word.Range range in _wordApp.ActiveDocument.StoryRanges)
{
Word.Range story = range;
while (story != null)
{
foreach (Word.Field field in story.Fields)
{
if (field.Type == Word.WdFieldType.wdFieldMergeField)
{
ProcessField(field.Code.Text);
}
}
story = story.NextStoryRange;
}
}

Unfortunately, if section 1's Header is blank but there is a section 2
Header, the above code doesn't work. It does not pick up the existence
of the section 2's Header

  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default Is there a workaround for a bug with automation related to StoryRanges

While I have never seen code like yours, you might try:
Sub ScratchMacro()
Dim pRange As Word.Range
Dim oFld As Word.Field
Dim iLink As Long
iLink = ActiveDocument.Sections(1).Headers(1).Range.StoryT ype * I don't
know why, but this line is supposed to correct the issue of blank/skip
header and footers.
For Each pRange In ActiveDocument.StoryRanges
Do
For Each oFld In pRange.Fields
Select Case oFld.Type
Case wdFieldMergeField
MsgBox "Field found"
'Do your deed here.
Case Else
'Do nothing
End Select
Next
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next
End Sub



PromisedOyster wrote:
The following code iterates through all merge fields:

foreach (Word.Range range in _wordApp.ActiveDocument.StoryRanges)
{
Word.Range story = range;
while (story != null)
{
foreach (Word.Field field in story.Fields)
{
if (field.Type == Word.WdFieldType.wdFieldMergeField)
{
ProcessField(field.Code.Text);
}
}
story = story.NextStoryRange;
}
}

Unfortunately, if section 1's Header is blank but there is a section 2
Header, the above code doesn't work. It does not pick up the existence
of the section 2's Header


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Is there a workaround for a bug with automation related to StoryRanges

See the article "Using a macro to replace text where ever it appears in a
document including Headers, Footers, Textboxes, etc." at:

http://www.word.mvps.org/FAQs/Macros...AllWithVBA.htm


--
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

"PromisedOyster" wrote in message
ups.com...
The following code iterates through all merge fields:

foreach (Word.Range range in _wordApp.ActiveDocument.StoryRanges)
{
Word.Range story = range;
while (story != null)
{
foreach (Word.Field field in story.Fields)
{
if (field.Type == Word.WdFieldType.wdFieldMergeField)
{
ProcessField(field.Code.Text);
}
}
story = story.NextStoryRange;
}
}

Unfortunately, if section 1's Header is blank but there is a section 2
Header, the above code doesn't work. It does not pick up the existence
of the section 2's Header



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
Word's User Process shutdown Automation process Yehuda Microsoft Word Help 0 August 17th 05 10:05 PM
Sorting a table while keeping some related rows together Dan Corban Tables 7 January 20th 05 07:31 PM


All times are GMT +1. The time now is 12:35 PM.

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"