#1
|
|||
|
|||
replacing fields with fields
i have a bevy of document templates written using TheFormTool and in .dotx format. TheFormTool is a microsoft word add in.
It uses word's mail merge coding to create variable placeholders. i wrote a bunch of templates and now want to make some changes with find and replace across the whole lot. i have used "vba find and replace 2.1" by mr. greg maxey in the past with much success...just not with entire merge fields. i have also tried to use mr. graham mayor's (interestingly that they share the same intitials) "batch process v. 4.7" without success. both with and without field coding showing...all to no avail. any suggestions? i have attached a document with the sought find and replace contents. |
#2
|
||||
|
||||
It is by no means apparent from your post or its attachments what is to be found and what the found content is to be replaced with. Moreover, there isn't a single MERGEFIELD in either document.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
Neither Greg's nor my batch process will handle field replacement as you seem to be attempting.
I suspect Paul is not familiar with the add-ins however what is being searched for is a sequence of field structures similar to { IF "TFT<CourtDistrict> Type<Open> Format<Freeform> Condition<CourtDistrict:EQ1> Item<> Column<> Math<> BL<> Offset<> Done<> Ver<03.00> ResetResult<{if:>" <> "x" "{if:" "x" \* MERGEFORMAT }FIRST{ IF "TFT Type<Close>" <> "x" "}" "x" \* MERGEFORMAT } each to be replaced with %, then a sequence of %%%%% (presumably the result of replacing all those fields) to be replaced with another complex field structure. Greg and I are friends of many years standing and have co-developed several processes including this one - our corresponding initials are coincidental.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#4
|
||||
|
||||
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Paul, i apologize for my ignorance and mislabeling. i thought that the fields were in fact word MERGEFIELDS.
in any event, as Graham deduced, i am attempting to take the items located in the left columns and replace them with the items in the right. the "%" are meant to simply be temporary placeholders for the final pass. they are done incrementally to attempt to avoid the 255 character find limit. TheFormTool has a find and replace function (written in VBA) that allows one to copy the replace text to the clipboard and then highlight the find text thereafter....and it works with the pseudo mergefields. It however, does not have the ability to batch convert a set of documents simultaneously. hope that helps clear up things a bit. again, any help is greatly appreciated. if nothing else, thank you Graham and Paul for all the talent that you share with others. |
#6
|
||||
|
||||
Presumably, you're only trying tp replace part or parts of each field's code. If you tell us precisely what needs to be changed, we might be able to help with that.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
i have attached a document which contains the specific find and replace terms.
i am actually trying to replace the entire field's coding, not a portion thereof. |
#8
|
||||
|
||||
So you want all four of your fields replaced with the one field? Are there other similarly-constructed fields beginning with 'IF "TFT' that should not be changed?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
yes, to both. Yes, i would like for all four of your fields replaced with the one field and yes, each template has a host of pseudo merge fields that begin with 'IF "TFT' that should not be changed.
that would have been nice for a wildcard search with * to solve it. The solution still evades me. Presently i am having to manual change each template....which is rather tedious. |
#10
|
||||
|
||||
Quote:
{ IF "TFT<CourtDistrict> Type<Open> Format<Freeform> Condition<CourtDistrict:EQ1> Item<> Column<> Math<> BL<> Offset<> Done<> Ver<03.00> ResetResult<{if:>" <> "x" "{if:" "x" \* MERGEFORMAT } with changes in the EQ number, and { IF "TFT Type<Close>" <> "x" "}" "x" \* MERGEFORMAT } both of which are repeated four times. It's not apparent whether both of the above are to be replaced and whether that replacement is with just the one field to replace the pair, viz: { IF "TFT<[AuroraDatabase.CountyCircuitDistrict$.DistrictNumb er]> Type<Text> Format<Uppercase> Condition<> Layer<0> Item<X> Column<> Math<> BL<N> Offset<> Done<> ResetResult<{DISTRICTNUMBER¬X}>" <> "x" "{DISTRICTNUMBERX}" "x" \* MERGEFORMAT } or whether the fields are to be individually replaced with that field. As for: Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
the fields to be found and replaced have the "Condition<CourtDistrict:EQ#>" where # is a number 1 through 5.
please see attached screenshot of the revealed coding and i resubmitted the find and replace pairs with the highlighting included. |
#12
|
||||
|
||||
Try the following.
All you need do is ensure the first paragraph in the document you're running the code from (which shouldn't be one of the documents that need updating) contains the replacement string (i.e. from 'IF "TFT<[AuroraDatabase' to '\* MERGEFORMAT'). The only reason for that stipulation is that your replacement string employs mixed fonts (e.g. TNR & Wingdings). Code:
Sub UpdateDocuments() Application.ScreenUpdating = False Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document strFolder = GetFolder If strFolder = "" Then Exit Sub ActiveWindow.View.ShowFieldCodes = True With ActiveDocument strDocNm = .FullName .Range(0, .Paragraphs(1).Range.End - 1).Copy End With strFile = Dir(strFolder & "\*.doc", vbNormal) Do While strFile <> "" If strFolder & "\" & strFile <> strDocNm Then Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False) With wdDoc With .Range.Find .ClearFormatting .Replacement.ClearFormatting .Text = "IF ""TFT[!^019^021]@\<CourtDistrict:EQ[0-9]\>*MERGEFORMAT" .Replacement.Text = "^c" .Forward = True .Wrap = wdFindContinue .Format = False .MatchWildcards = True .Execute Replace:=wdReplaceAll End With .Close SaveChanges:=True End With End If strFile = Dir() Loop Set wdDoc = Nothing ActiveWindow.View.ShowFieldCodes = False Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Paul,
Good morning. Well it seems we are making progress, but not there just yet. I have attached a sample template that was processed using the code you provided. In an effort to assist you I have also provided the unadulterated version. It seems to me that the code stripped the first portion of the field coding....but not the later. perhaps it must be run in a loop....feel silly suggesting such to you. In any event, thanks for your consideration. |
#14
|
||||
|
||||
OK, I've made some minor changes to the previous instructions. Try the update (see bolded bits).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
Paul, i followed your directions, as i understood them - to no avail.
the results are attached in the document in the following posting...it is in fact manipulating the data fields that i want...just not to the extent hoped for. i do appreciate the effort you are putting in this project as it is something that i would not be able to accomplish in my lifetime. |
Tags |
find and replace, merge fields, vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How can I set up tab to go back and forth between legacy fields and content control fields in a Word | Ikajed | Word | 1 | 10-13-2017 06:06 PM |
Displaying FORMTEXT fields when merge fields are empty or null | sfkHooper | Mail Merge | 6 | 01-19-2016 04:24 PM |
Macro to keep formatted form fields after mail merge or replace text with formatted form fields | jer85 | Word VBA | 2 | 04-05-2015 10:00 PM |
Word 2010 - DOCX File with fields -> PDF with fields | senglory | Word | 2 | 03-27-2012 10:10 AM |
fields | vishalvijayan | Word | 1 | 03-30-2011 12:02 PM |