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

Posted on 2011-05-03
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
    LVL 1

    Expert Comment

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

    Author Comment

    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.

    LVL 9

    Expert Comment

    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


    Author Comment

    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.
    LVL 1

    Expert Comment

    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
    LVL 9

    Expert Comment

    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


    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 30

    Accepted Solution

    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

    Excellent solution

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
    Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
    This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
    This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now