Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Word's User Process shutdown Automation process | Microsoft Word Help | |||
Sorting a table while keeping some related rows together | Tables |