[Last Call] Learn how to a build a cloud-first strategyRegister Now


"Find & Insert" instead of "Find & Replace" in a Word doc

Posted on 2011-05-03
Medium Priority
Last Modified: 2012-05-11
How do I "Find" a text block and "Insert" new text or special characters without deleting the found text?

I want to  "Find & Insert" instead of "Find & Replace" .
Question by:mycomac
  • 4
  • 2
  • 2
  • +1

Expert Comment

ID: 35513060
why not just replace with what you want to be there: find "X" replace with "X+Y"?

Author Comment

ID: 35513219
I apologize. I should have offer more detail in my question.  

Following is an example of a header in the document, formatted Arial-Bold-20pt:

..."March 29, 2010 Nitrogen Levels"...

Specifically, I want to "Find" all text that is formatted Arial-Bold-20pt and insert a page break BEFORE this text, leaving the text intact.

The real basic question is how to find a block of text with defined parameters (like a heading block), and insert new text &/or special characters before or after that text without deleting the text.

The trick is that the "Find" text could be variable, especially if searching based on text format, or if a variable date is used in the text.


Expert Comment

ID: 35513354
Find and Replace
have this type of functionality to use it.

March 29, 2010 Nitrogen Levels

place this in Find What

now press More>>

Replace -----
Format -- choose user format setting for Finding  March 29, 2010 Nitrogen Levels   word

Replace With
March 29, 2010 Nitrogen Levels

Replace ----
Format  --choose user format setting for Finding  March 29, 2010 Nitrogen Levels   word that is after replace it is same as before only you need to add Special button press and select your special character.

Finally Replace or Replace ALL

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.


Author Comment

ID: 35513451
I apologize, but I have not been clear with my question.

"March 29, 2010 Nitrogen Levels" is variable - so there are other headers that will be similar, but not identical - like "October 3, 2010 Nitrogen Levels", or "2010 Average Nitrogen Levels".  The only similarity these various text blocks have are that they contain the words "Nitrogen Levels", and that they are formatted to Arial-Bold-20pt.

I want to find all of the blocks of text (variable) that are formatted to Arial-Bold-20pt and insert a page break before every one of those text blocks without making any changes to that text.

Expert Comment

ID: 35513808
the function itself doesn't see formatting, only strings of ascii chars.

simplest solution:

1 Find "Nitrogen Levels"
2 click to where you want the page break
3 ctrl+enter
4 click the "find next" button
5 if you have more breaks to insert repeat 2-5

Expert Comment

ID: 35513816
this is sample ... but you need to investigate it

Sub DocVarExists()
    Dim varName As String
    Dim dummy As String

    varName = InputBox("Enter variable name:", "DocVariable Test")
    If Len(varName) = 0 Then Exit Sub

    On Error Resume Next
    dummy = ActiveDocument.Variables(varName)
    If Err.Number = 0 Then   ' it exists
        Selection.Fields.Add Range:=Selection.Range, _
            Type:=wdFieldDocVariable, Text:=varName
    Else  ' it doesn't exist
        MsgBox "Variable " & varName & " doesn't exist"
    End If
End Sub


Author Comment

ID: 35514404

Thanks for your response.  I think this is on the right track, but 2 questions.

1.  How would I select the text based on it's formatting, if that is the best identifying factor to select with?

2. How would this allow me to specify what to insert, and to select "insert before" or "insert after" the selected text?

I want to run this as a batch, not individually for each instance of the text.
LVL 33

Accepted Solution

Paul Sauvé earned 2000 total points
ID: 35517849
Perhaps you coul use the approach of search for a carriage return (^p)  with the format Arial-Bold-20pt and replace it with the same thing (format Arial-Bold-20pt) and adding the Format - Paragraph - Lines and page breaks - Page break Before: How to Before.docx

Author Closing Comment

ID: 35546433
Excellent solution

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question