Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 81
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, 8 views)
Reply With Quote
 



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

All times are GMT -7. The time now is 08:49 AM.


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