Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Changing field results without automatic change to the field?
Hi all,
First of all, thank you to Graham for answering my question earlier. I have one more that's sort of in the same vein, but I'm not sure if it's exactly the same thing. You know how Word adds a MERGEFORMAT field when you select a field and apply new formatting to it? I looked that up and found out that was an automatic change that you can undo and still keep the formatting. Is there a way to turn off that automatic change, so you can change formatting temporarily, but then it can go back to the original form on the next update because there's no MERGEFORMAT switch added? I have lots of fields this would apply to, and it would be a real pain to go through all of them and remove the MERGEFORMAT. Thanks again! Jezzica85 |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Changing field results without automatic change to the field?
I am not sure what you are asking here - but removal of mergeformat switches
is simple enough. The following macro will remove the switches or replace the with charformat switches. See the notes in the macro. http://www.gmayor.com/installing_macro.htm Sub ChangeSwitch() Dim oRng As Range Dim iFld As Integer Dim strChoice As String Selection.HomeKey ActiveDocument.ActiveWindow.View.ShowFieldCodes = True strChoice = MsgBox("Replace Mergeformat switch with Charformat switch?" _ & vbCr & "Click 'No' to remove formatting switch completely", _ vbYesNoCancel, "Replace Formatting Switch") If strChoice = 2 Then GoTo UserCancelled If strChoice = vbYes Then For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) 'The following line sets the field type on which the macro operates 'Remove the line to work on all fields If .Type = wdFieldMergeField Then If InStr(1, .Code, "MERGEFORMAT") 0 Then .Code.Text = replace(.Code.Text, "MERGEFORMAT", "CHARFORMAT") End If If InStr(1, .Code, "CHARFORMAT") = 0 Then .Code.Text = .Code.Text & " \* CHARFORMAT " End If ' The following block, if activated will apply a particular style to the field(s) ' Here 'Heading 1 style" ' .Code.Select ' Set oRng = Selection.Range ' With oRng ' .Start = oRng.Characters(1).Start ' .End = oRng.Characters(2).End ' .Style = "Heading 1" ' End With .Update End If End With Next iFld End If If strChoice = vbNo Then For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) 'The following line sets the field type on which the macro operates 'Remove the line to work on all fields If .Type = wdFieldMergeField Then If InStr(1, .Code, "MERGEFORMAT") 0 Then .Code.Text = replace(.Code.Text, "\* MERGEFORMAT", "") End If If InStr(1, .Code, "CHARFORMAT") 0 Then .Code.Text = replace(.Code.Text, " \* CHARFORMAT ", "") End If .Update End If End With Next iFld End If ActiveDocument.ActiveWindow.View.ShowFieldCodes = False Exit Sub UserCancelled: MsgBox "User Cancelled", vbInformation, "Replace Formatting Switch" End Sub jezzica85 wrote: Hi all, First of all, thank you to Graham for answering my question earlier. I have one more that's sort of in the same vein, but I'm not sure if it's exactly the same thing. You know how Word adds a MERGEFORMAT field when you select a field and apply new formatting to it? I looked that up and found out that was an automatic change that you can undo and still keep the formatting. Is there a way to turn off that automatic change, so you can change formatting temporarily, but then it can go back to the original form on the next update because there's no MERGEFORMAT switch added? I have lots of fields this would apply to, and it would be a real pain to go through all of them and remove the MERGEFORMAT. Thanks again! Jezzica85 |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Changing field results without automatic change to the field?
Thank you again Graham!
That wasn't exactly what I needed, but it had everything in there, so I used pieces of your code to get mine to work. Thanks a million again! Jezzica85 "Graham Mayor" wrote: I am not sure what you are asking here - but removal of mergeformat switches is simple enough. The following macro will remove the switches or replace the with charformat switches. See the notes in the macro. http://www.gmayor.com/installing_macro.htm Sub ChangeSwitch() Dim oRng As Range Dim iFld As Integer Dim strChoice As String Selection.HomeKey ActiveDocument.ActiveWindow.View.ShowFieldCodes = True strChoice = MsgBox("Replace Mergeformat switch with Charformat switch?" _ & vbCr & "Click 'No' to remove formatting switch completely", _ vbYesNoCancel, "Replace Formatting Switch") If strChoice = 2 Then GoTo UserCancelled If strChoice = vbYes Then For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) 'The following line sets the field type on which the macro operates 'Remove the line to work on all fields If .Type = wdFieldMergeField Then If InStr(1, .Code, "MERGEFORMAT") 0 Then .Code.Text = replace(.Code.Text, "MERGEFORMAT", "CHARFORMAT") End If If InStr(1, .Code, "CHARFORMAT") = 0 Then .Code.Text = .Code.Text & " \* CHARFORMAT " End If ' The following block, if activated will apply a particular style to the field(s) ' Here 'Heading 1 style" ' .Code.Select ' Set oRng = Selection.Range ' With oRng ' .Start = oRng.Characters(1).Start ' .End = oRng.Characters(2).End ' .Style = "Heading 1" ' End With .Update End If End With Next iFld End If If strChoice = vbNo Then For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) 'The following line sets the field type on which the macro operates 'Remove the line to work on all fields If .Type = wdFieldMergeField Then If InStr(1, .Code, "MERGEFORMAT") 0 Then .Code.Text = replace(.Code.Text, "\* MERGEFORMAT", "") End If If InStr(1, .Code, "CHARFORMAT") 0 Then .Code.Text = replace(.Code.Text, " \* CHARFORMAT ", "") End If .Update End If End With Next iFld End If ActiveDocument.ActiveWindow.View.ShowFieldCodes = False Exit Sub UserCancelled: MsgBox "User Cancelled", vbInformation, "Replace Formatting Switch" End Sub jezzica85 wrote: Hi all, First of all, thank you to Graham for answering my question earlier. I have one more that's sort of in the same vein, but I'm not sure if it's exactly the same thing. You know how Word adds a MERGEFORMAT field when you select a field and apply new formatting to it? I looked that up and found out that was an automatic change that you can undo and still keep the formatting. Is there a way to turn off that automatic change, so you can change formatting temporarily, but then it can go back to the original form on the next update because there's no MERGEFORMAT switch added? I have lots of fields this would apply to, and it would be a real pain to go through all of them and remove the MERGEFORMAT. Thanks again! Jezzica85 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Field results question | Microsoft Word Help | |||
Word field codes and results BOTH appear | Microsoft Word Help | |||
how do i edit a merged results field | Mailmerge | |||
Saving word document with field results not field codes | Microsoft Word Help | |||
FILLIN Field Results | Microsoft Word Help |