• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

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

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" .
0
mycomac
Asked:
mycomac
  • 4
  • 2
  • 2
  • +1
1 Solution
 
KatastrofCommented:
why not just replace with what you want to be there: find "X" replace with "X+Y"?
0
 
mycomacAuthor Commented:
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.

0
 
sarabhaiCommented:
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

Now
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




0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
mycomacAuthor Commented:
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.
0
 
KatastrofCommented:
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
0
 
sarabhaiCommented:
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

0
 
mycomacAuthor Commented:
sarabhai,

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.
0
 
Paul SauvéRetiredCommented:
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
After.docx
0
 
mycomacAuthor Commented:
Excellent solution
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now