Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-24-2021, 11:40 AM
ladracer ladracer is offline replacing fields with fields Windows 10 replacing fields with fields Office 2010
Novice
replacing fields with fields
 
Join Date: Mar 2021
Posts: 18
ladracer is on a distinguished road
Default 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.
Attached Files
File Type: docx QuickList1.docx (20.4 KB, 7 views)
File Type: docx Find and Replace Pairs Table.docx (53.1 KB, 7 views)
Reply With Quote
  #2  
Old 03-24-2021, 03:03 PM
macropod's Avatar
macropod macropod is offline replacing fields with fields Windows 10 replacing fields with fields Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 03-24-2021, 10:31 PM
gmayor's Avatar
gmayor gmayor is offline replacing fields with fields Windows 10 replacing fields with fields Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #4  
Old 03-25-2021, 04:38 AM
macropod's Avatar
macropod macropod is offline replacing fields with fields Windows 10 replacing fields with fields Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by gmayor View Post
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 }
I could see such content in the document by toggling Word's field code display 'on', but there are no MERGEFIELDs there - or anywhere else in the document. Hence it is not apparent what the OP is trying to do.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-25-2021, 04:55 AM
ladracer ladracer is offline replacing fields with fields Windows 10 replacing fields with fields Office 2010
Novice
replacing fields with fields
 
Join Date: Mar 2021
Posts: 18
ladracer is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 03-25-2021, 05:05 AM
macropod's Avatar
macropod macropod is offline replacing fields with fields Windows 10 replacing fields with fields Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #7  
Old 03-25-2021, 05:19 AM
ladracer ladracer is offline replacing fields with fields Windows 10 replacing fields with fields Office 2010
Novice
replacing fields with fields
 
Join Date: Mar 2021
Posts: 18
ladracer is on a distinguished road
Default

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.
Attached Files
File Type: docx Find and Replace List.docx (18.2 KB, 7 views)
Reply With Quote
  #8  
Old 03-25-2021, 01:46 PM
macropod's Avatar
macropod macropod is offline replacing fields with fields Windows 10 replacing fields with fields Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #9  
Old 03-27-2021, 05:23 AM
ladracer ladracer is offline replacing fields with fields Windows 10 replacing fields with fields Office 2010
Novice
replacing fields with fields
 
Join Date: Mar 2021
Posts: 18
ladracer is on a distinguished road
Default

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.
Reply With Quote
  #10  
Old 03-27-2021, 06:06 AM
macropod's Avatar
macropod macropod is offline replacing fields with fields Windows 10 replacing fields with fields Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by ladracer View Post
each template has a host of pseudo merge fields that begin with 'IF "TFT' that should not be changed.
In which case all we need to know is what characteristics of the fields you want to update differentiate them from the ones you don't. As it is, there are essentially only two field codes in what you've designated as to be found:
{ 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" "{DISTRICTNUMBERX}" "x" \* MERGEFORMAT }
or whether the fields are to be individually replaced with that field.

As for:
Quote:
they are done incrementally to attempt to avoid the 255 character find limit
None of your Find or Replace field codes has reached that limit.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 03-27-2021, 06:38 AM
ladracer ladracer is offline replacing fields with fields Windows 10 replacing fields with fields Office 2010
Novice
replacing fields with fields
 
Join Date: Mar 2021
Posts: 18
ladracer is on a distinguished road
Default

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.
Attached Images
File Type: png field coding find and replace.PNG (105.1 KB, 22 views)
Attached Files
File Type: docx Find and Replace List.docx (18.4 KB, 5 views)
Reply With Quote
  #12  
Old 03-27-2021, 02:40 PM
macropod's Avatar
macropod macropod is offline replacing fields with fields Windows 10 replacing fields with fields Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #13  
Old 03-30-2021, 08:15 AM
ladracer ladracer is offline replacing fields with fields Windows 10 replacing fields with fields Office 2010
Novice
replacing fields with fields
 
Join Date: Mar 2021
Posts: 18
ladracer is on a distinguished road
Default

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.
Attached Files
File Type: dotx Unadulterated and Modified Versions.dotx (41.4 KB, 5 views)
Reply With Quote
  #14  
Old 03-31-2021, 06:52 PM
macropod's Avatar
macropod macropod is offline replacing fields with fields Windows 10 replacing fields with fields Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

OK, I've made some minor changes to the previous instructions. Try the update (see bolded bits).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #15  
Old 04-01-2021, 05:21 AM
ladracer ladracer is offline replacing fields with fields Windows 10 replacing fields with fields Office 2010
Novice
replacing fields with fields
 
Join Date: Mar 2021
Posts: 18
ladracer is on a distinguished road
Default

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.
Reply With Quote
Reply

Tags
find and replace, merge fields, vba

Thread Tools
Display Modes


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
replacing fields with fields 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
replacing fields with fields fields vishalvijayan Word 1 03-30-2011 12:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:58 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft