Reply
 
Thread Tools Display Modes
  #1   Report Post  
S.P.
 
Posts: n/a
Default lock/unlink MailMerge.fields in header

I want to do a one-time (no update) MailMerge, into the existing document.
The permanent "locking" almost works with

Set myFields = ActiveDocument.Fields ' or ActiveDocument.MailMerge.Fields
?!?
For Each fn in myFields
If fn.type = wdFieldMergeField Then
fn.Unlink
End If
Next fn

Problem: the Fields in the header are not affected (which is good for page
numbers...but for that I have the " If fn.type = ..." ).

-- How can I unlink Mergefields in headers?

I just can't find the ActiveDocument.Fields equivalent for headers.


  #2   Report Post  
Charles Kenyon
 
Posts: n/a
Default

The following works for Ref field updating and should give you a leg up.
Private Sub RefFieldUpdateAllStory()
' Written by Charles Kyle Kenyon 15 November 2001
' repaired by Jezebel
' All Story Field Updater - Ref fields
Dim oField As Field
Dim oStory As Range
'
For Each oStory In ActiveDocument.StoryRanges
' This goes into headers and footers as well as the regular document
Do
For Each oField In oStory.Fields
If oField.Type = wdFieldRef Then
oField.Update
End If
Next oField
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next oStory
End Sub

--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"S.P." wrote in message
...
I want to do a one-time (no update) MailMerge, into the existing document.
The permanent "locking" almost works with

Set myFields = ActiveDocument.Fields ' or
ActiveDocument.MailMerge.Fields ?!?
For Each fn in myFields
If fn.type = wdFieldMergeField Then
fn.Unlink
End If
Next fn

Problem: the Fields in the header are not affected (which is good for page
numbers...but for that I have the " If fn.type = ..." ).

-- How can I unlink Mergefields in headers?

I just can't find the ActiveDocument.Fields equivalent for headers.



  #3   Report Post  
Charles Kenyon
 
Posts: n/a
Default

I haven't tested this yet:

Sub MergeFieldLockAllStory()
' Written by Charles Kyle Kenyon 1 April 2005
'
' All Story Field Locker - Merge fields
Dim oField As Field
Dim oStory As Range
' On Error Resume Next
For Each oStory In ActiveDocument.StoryRanges
' This goes into headers and footers as well as the regular document
Do
For Each oField In oStory.Fields
If oField.Type = wdFieldMergeField Then
oField.Lock
End If
Next oField
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next oStory
End Sub
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"S.P." wrote in message
...
I want to do a one-time (no update) MailMerge, into the existing document.
The permanent "locking" almost works with

Set myFields = ActiveDocument.Fields ' or
ActiveDocument.MailMerge.Fields ?!?
For Each fn in myFields
If fn.type = wdFieldMergeField Then
fn.Unlink
End If
Next fn

Problem: the Fields in the header are not affected (which is good for page
numbers...but for that I have the " If fn.type = ..." ).

-- How can I unlink Mergefields in headers?

I just can't find the ActiveDocument.Fields equivalent for headers.



  #4   Report Post  
Charles Kenyon
 
Posts: n/a
Default

Otherwise, you might consider a more drastic option.

Sub UnmergeThis()
' Written 29 August 2002 by Charles Kyle Kenyon
' Updated 23 September 2002 to attach normal.dot
' Remove merge codes from document, remove from merge status
'
' Test for template - in template only disconnect from merge but leave
merge fields active
'
On Error Resume Next
If ActiveDocument.Type = wdTypeTemplate Then
'
' Test for merge document - do not run if not merge document
'
If MergeTest() = False Then ' private function call
Exit Sub
End If
'
' Disconnect template from merge data
ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
Application.CommandBars("MergeK").Visible = False
Exit Sub
End If
'
' Test for merge document - do not run if not merge document
'
If MergeTest() = False Then
Exit Sub
End If
'
Dim oField As Field
Dim vMsgBoxResponse As Variant
Dim sUserTemplates As String
'
' Double check with user because permanent operation
'
vMsgBoxResponse = MsgBox(Prompt:= _
"This will disconnect this document from the merge file." _
& vbCrLf & "This cannot be undone." & vbCrLf & vbCrLf _
& "Continue?", Buttons:= _
vbQuestion + vbYesNo + vbDefaultButton1, _
Title:="Continue?")
If vMsgBoxResponse vbYes Then
MsgBox Prompt:="No changes made to document.", _
Title:="Merge connection still active."
Exit Sub
End If
'
' OK to continue
'
Application.ScreenUpdating = False
'
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldMergeField Then
oField.Unlink
End If
Next oField
'
ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
'
' Disconnect from template - attach normal.dot
'
sUserTemplates =
Application.Options.DefaultFilePath(wdUserTemplate sPath)
If Right(sUserTemplates, 1) "\" Then
sUserTemplates = sUserTemplates & "\"
End If
' sUserTemplates =
Application.Options.DefaultFilePath(wdUserTemplate sPath) & "\"
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = sUserTemplates & "Normal.dot"
End With
Application.ScreenUpdating = True
Application.ScreenRefresh
'
End Sub
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"S.P." wrote in message
...
I want to do a one-time (no update) MailMerge, into the existing document.
The permanent "locking" almost works with

Set myFields = ActiveDocument.Fields ' or
ActiveDocument.MailMerge.Fields ?!?
For Each fn in myFields
If fn.type = wdFieldMergeField Then
fn.Unlink
End If
Next fn

Problem: the Fields in the header are not affected (which is good for page
numbers...but for that I have the " If fn.type = ..." ).

-- How can I unlink Mergefields in headers?

I just can't find the ActiveDocument.Fields equivalent for headers.



  #5   Report Post  
Charles Kenyon
 
Posts: n/a
Default

Correction:

Sub MergeFieldLockAllStory()
' Written by Charles Kyle Kenyon 1 April 2005
'
' All Story Field Locker - Merge fields
Dim oField As Field
Dim oStory As Range
' On Error Resume Next
For Each oStory In ActiveDocument.StoryRanges
' This goes into headers and footers as well as the regular document
Do
For Each oField In oStory.Fields
If oField.Type = wdFieldMergeField Then
oField.Locked = True
End If
Next oField
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next oStory
End Sub

Apparently there is not a lock method but there is a locked property. I now
have tested, briefly.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"Charles Kenyon" wrote in
message ...
I haven't tested this yet:

Sub MergeFieldLockAllStory()
' Written by Charles Kyle Kenyon 1 April 2005
'
' All Story Field Locker - Merge fields
Dim oField As Field
Dim oStory As Range
' On Error Resume Next
For Each oStory In ActiveDocument.StoryRanges
' This goes into headers and footers as well as the regular document
Do
For Each oField In oStory.Fields
If oField.Type = wdFieldMergeField Then
oField.Lock
End If
Next oField
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next oStory
End Sub
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"S.P." wrote in message
...
I want to do a one-time (no update) MailMerge, into the existing document.
The permanent "locking" almost works with

Set myFields = ActiveDocument.Fields ' or
ActiveDocument.MailMerge.Fields ?!?
For Each fn in myFields
If fn.type = wdFieldMergeField Then
fn.Unlink
End If
Next fn

Problem: the Fields in the header are not affected (which is good for
page numbers...but for that I have the " If fn.type = ..." ).

-- How can I unlink Mergefields in headers?

I just can't find the ActiveDocument.Fields equivalent for headers.







  #6   Report Post  
S.P.
 
Posts: n/a
Default

Thank you so much!
I found your own (!) examples at
http://www.addbalance.com/word/faq_s...m#updatefields
The solution was the "StoryRanges", and the nested loop
Here's the working Script:


Set MM = ActiveDocument.MailMerge

MM.OpenDataSource Name:="c:\pdb.mer"
MM.ViewMailMergeFieldCodes = False
MM.DataSource.Close

For Each SR In ActiveDocument.StoryRanges
For Each F In SR.Fields
If F.Type = wdFieldMergeField Then
F.Unlink
End If
Next F
Next SR

End Sub




"Charles Kenyon" schrieb im
Newsbeitrag ...
The following works for Ref field updating and should give you a leg up.
Private Sub RefFieldUpdateAllStory()
' Written by Charles Kyle Kenyon 15 November 2001
' repaired by Jezebel
' All Story Field Updater - Ref fields
Dim oField As Field
Dim oStory As Range
'
For Each oStory In ActiveDocument.StoryRanges
' This goes into headers and footers as well as the regular document
Do
For Each oField In oStory.Fields
If oField.Type = wdFieldRef Then
oField.Update
End If
Next oField
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next oStory
End Sub

--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"S.P." wrote in message
...
I want to do a one-time (no update) MailMerge, into the existing document.
The permanent "locking" almost works with

Set myFields = ActiveDocument.Fields ' or
ActiveDocument.MailMerge.Fields ?!?
For Each fn in myFields
If fn.type = wdFieldMergeField Then
fn.Unlink
End If
Next fn

Problem: the Fields in the header are not affected (which is good for
page numbers...but for that I have the " If fn.type = ..." ).

-- How can I unlink Mergefields in headers?

I just can't find the ActiveDocument.Fields equivalent for headers.





  #7   Report Post  
Charles Kenyon
 
Posts: n/a
Default

There is a difference between unlink and lock. The difference is that
locking maintains the field structure and you can later unlock. This may not
matter with what you are doing. For me, it often does matter. Unlinking,
essentially, is permanent. On the other hand, it is a method rather than a
property.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"S.P." wrote in message
...
Thank you so much!
I found your own (!) examples at
http://www.addbalance.com/word/faq_s...m#updatefields
The solution was the "StoryRanges", and the nested loop
Here's the working Script:


Set MM = ActiveDocument.MailMerge

MM.OpenDataSource Name:="c:\pdb.mer"
MM.ViewMailMergeFieldCodes = False
MM.DataSource.Close

For Each SR In ActiveDocument.StoryRanges
For Each F In SR.Fields
If F.Type = wdFieldMergeField Then
F.Unlink
End If
Next F
Next SR

End Sub




"Charles Kenyon" schrieb im
Newsbeitrag ...
The following works for Ref field updating and should give you a leg up.
Private Sub RefFieldUpdateAllStory()
' Written by Charles Kyle Kenyon 15 November 2001
' repaired by Jezebel
' All Story Field Updater - Ref fields
Dim oField As Field
Dim oStory As Range
'
For Each oStory In ActiveDocument.StoryRanges
' This goes into headers and footers as well as the regular document
Do
For Each oField In oStory.Fields
If oField.Type = wdFieldRef Then
oField.Update
End If
Next oField
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next oStory
End Sub

--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"S.P." wrote in message
...
I want to do a one-time (no update) MailMerge, into the existing
document.
The permanent "locking" almost works with

Set myFields = ActiveDocument.Fields ' or
ActiveDocument.MailMerge.Fields ?!?
For Each fn in myFields
If fn.type = wdFieldMergeField Then
fn.Unlink
End If
Next fn

Problem: the Fields in the header are not affected (which is good for
page numbers...but for that I have the " If fn.type = ..." ).

-- How can I unlink Mergefields in headers?

I just can't find the ActiveDocument.Fields equivalent for headers.







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
Page Number and Page header on the first page Frank Drost Formatting Long Documents 3 March 1st 05 02:17 PM
Header changes with text outside of header Connie Martin Microsoft Word Help 3 February 22nd 05 06:58 PM
Header and Footer robin Microsoft Word Help 4 January 12th 05 04:17 PM
How do I reformat a header on page 2 to be different from the hea. Ckanegae Microsoft Word Help 1 December 28th 04 10:43 PM
Same header but even/odd footer (sorry for the new thread) B?atrice Karjalainen Page Layout 1 December 16th 04 12:40 AM


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