#1
|
|||
|
|||
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 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 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 |
#2
|
||||
|
||||
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.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
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! |
#4
|
||||
|
||||
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 |
#5
|
|||
|
|||
Argh... I think Windows Defender is blocking Greg's CCTool. I can't download it with Chrome or with Edge.
|
|
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 |
Find what box in Find and replace limits the length of a search term | Hoxton118 | Word VBA | 7 | 06-10-2014 05:05 AM |
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 |