Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-01-2021, 10:22 AM
Steve Kunkel Steve Kunkel is offline In Find and Replace, Wrap is not acting as expected. Windows 10 In Find and Replace, Wrap is not acting as expected. Office 2019
Advanced Beginner
In Find and Replace, Wrap is not acting as expected.
 
Join Date: May 2019
Location: Seattle area
Posts: 44
Steve Kunkel is on a distinguished road
Default In Find and Replace, Wrap is not acting as expected.

Hi Folks,



I've attached the .dotm file. When the template is opened, a userform (FormMain) collects input from the user, then makes a bunch of replacements. "[n]" gets changed to the student's name, and so on. A function, "DoFindReplace," gets called for this.

The "[n]" codes (tokens?) exist in my QuickParts too, so after doing all the replacements, a bunch of Custom Properties are also created/assigned. Then, later when I'm working on the student's report, and insert a QuickPart, I can run an additional module called "FixParts." This reads the Custom Properties, and calls DoFindReplace, to put the student's information into the report.

This was all working nicely, but I wanted to speed up the Find and Replace function, so I tried to remove some redundancy... So now I have this in the FormMain code, and in the FixParts code:
Code:
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument ' Define these here, so they're not in the func.
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
       ' .Text = FindText
       ' .Replacement.Text = ReplaceText
        .Forward = True
        .Wrap = wdFindContinue
        .MatchWildcards = 0 'Never set this to true.
       ' .MatchCase = vCase
    End With
...then, inside the DoFindReplace function is the bare minimal:
Code:
Sub DoFindReplace(FindText As String, ReplaceText As String, vCase As String)
  'This module gets called from the MainForm code
    With Selection.Find
        .Text = FindText
        .Replacement.Text = ReplaceText
        .MatchCase = vCase
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
So.... The FormMain code still works as expected when I first create a document from the .dotm file. However the FixParts module is not working anymore. It will make the first replacement then stop. I have it assigned to a Ribbon button (Word 2019). If I keep clicking the button, it doesn't help. BUT if I click to a different place in the document and run FixParts again, then it does make ALL the replacements.

So I'm guessing that I'm not using the ".Wrap = wdFindContinue" at Line 18 correctly??

Sorry about the long post -- I can explain more if needed. File is attached. General recommendations are also welcomed. And folks are welcome to use the psych report template for personal use, if anyone has a use for it.
-Steve
Attached Files
File Type: dotm @PsychRep - to Share.dotm (93.8 KB, 1 views)
Reply With Quote
  #2  
Old 05-01-2021, 08:02 PM
Guessed's Avatar
Guessed Guessed is offline In Find and Replace, Wrap is not acting as expected. Windows 10 In Find and Replace, Wrap is not acting as expected. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,324
Guessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to behold
Default

Steve

If you've seen many of my posts on this forum, you will know that I often encourage people to use mapped Content Controls instead of more vba intensive methods. In the case of your template, I think that your question can be greatly simplified by using a mapped CC setup that relies on just 4 xml fields.

See the attached doc to see how this concept works. The first table contains mapped CCs which you can populate and you will see that the dependent table CCs all change with the gender since they are all mapped to the same field with common 'value' settings. You can then use these CCs throughout your document and include them in your building blocks to completely do away with the code you are asking about.

Any document you want to apply this solution to will need the embedded XML file but that is a relatively simple step that is taken care of by saving this document as a template or by using vba to create the XML in any already existing document.
Attached Files
File Type: docx SchoolReport_MappedXML_Demo.docx (51.2 KB, 1 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 05-02-2021, 07:51 AM
Steve Kunkel Steve Kunkel is offline In Find and Replace, Wrap is not acting as expected. Windows 10 In Find and Replace, Wrap is not acting as expected. Office 2019
Advanced Beginner
In Find and Replace, Wrap is not acting as expected.
 
Join Date: May 2019
Location: Seattle area
Posts: 44
Steve Kunkel is on a distinguished road
Default

Wow -- Thank you for your time on this Andrew! I will investigate the use of Content Controls. I was vaguely aware of them, but had not used them because I was afraid they would be too cumbersome to insert every time I add a bit of narrative to my boilerplate text.

It would be nice if they could be added "on the fly" while typing. For example if I type "Something FirstName something," and the "FirstName" instantly became the mapped control of that type. I did a bit of google searching in the past and didn't see a way to do that. As I'm typing this however, it occurs to me that maybe the CCs could be saved as QuickParts, and inserted by typing the name...

I shall experiment!

And I agree -- This is way cleaner than what I had going with the customproperties!
Reply With Quote
  #4  
Old 05-02-2021, 03:58 PM
Guessed's Avatar
Guessed Guessed is offline In Find and Replace, Wrap is not acting as expected. Windows 10 In Find and Replace, Wrap is not acting as expected. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,324
Guessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to behold
Default

You can save the CCs as either formatted autocorrects or as building blocks(eg. quick parts). The autocorrect option looks a little dodgy (flashing cursor for a second) so I would recommend the building block method.

Once each of the CCs are saved as building blocks, the on-the-fly method of inserting them is to type enough of the name that it is unique and press F3.

A completely robust implementation using this CC method will still include at least a couple of simple macros but I think the ease of use will be far better than the path you were previously using.

I used Greg Maxey's Content Control Tools to create the XML from the initial four CCs for the sake of the demo file I uploaded. Whilst you don't need that to carry forward on your exploration, the information on that page and the tool itself is very useful as you experiment with mapped CCs.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 05-02-2021, 04:22 PM
Steve Kunkel Steve Kunkel is offline In Find and Replace, Wrap is not acting as expected. Windows 10 In Find and Replace, Wrap is not acting as expected. Office 2019
Advanced Beginner
In Find and Replace, Wrap is not acting as expected.
 
Join Date: May 2019
Location: Seattle area
Posts: 44
Steve Kunkel is on a distinguished road
Default

Argh... I think Windows Defender is blocking Greg's CCTool. I can't download it with Chrome or with Edge.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you use the find and replace tool to find dates and times in Excel 2013? Jules90 Excel 3 04-14-2020 07:40 PM
In Find and Replace, can Word stop after each Replace? wardw Word 1 06-08-2017 02:47 PM
In Find and Replace, Wrap is not acting as expected. Find what box in Find and replace limits the length of a search term Hoxton118 Word VBA 7 06-10-2014 05:05 AM
In Find and Replace, Wrap is not acting as expected. Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
Task type relationships not acting as expected Rkramkowski Project 0 12-08-2005 10:40 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 02:40 AM.


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