Word find end of line

My match pattern has 4 parts :

    <1st part><2nd part><3rd part><4th part>

    Here,
     <1st part> = Fixed string "Fedora"
     <2nd part> = A 2 digit number "[0-9][0-9]"
     <3rd part> = Followed by a ":" symbol.
     <4th part> = one or more strings till the end of the current line. 

NOTE : <4th part> ends with the end of current line and contains only alphabets.

I’ve reached till here :

Fedora[0-9][0-9]?[a-z]*[A-Z]*^l>

But the last part — searching the end of the line — is not yielding the expected result. Note that I’m trying to get the end of the line when Word breaks the line automatically.

Where am I going wrong ?

Cindy Meister's user avatar

asked Sep 28, 2018 at 10:50

Abhishek Singh's user avatar

2

It seems to me you need:

Find = Fedora[0-9]{2}:*^l

or:

Find = Fedora[0-9]{2}:*[^l^13]

answered Sep 28, 2018 at 11:46

macropod's user avatar

macropodmacropod

12.6k2 gold badges9 silver badges21 bronze badges

2

There is no way to use Word’s built-in Find to locate the end of a line that’s been generated by Word’s automatic layout. The only kind of «end-of-line» that can be searched is the manual line break inserted by pressing Shift+Enter. The manual line break corresponds to the special Find character ^l.

If you need to Find and extend to the end of a line then you need to use a macro (VBA). The following sample code does what you need. Please note that with the code as it stands only the last occurrence of the search term will be selected when the macro finishes. You need to build the final result into it that you’re looking for.

Or, simply remove the Do While and Loop lines and the macro will find the first term.

Sub FindThenToEndOfLine()
    Dim r As Range, rDoc As Word.Range
    Dim bFound As Boolean

    bFound = True
    Set r = ActiveDocument.content
    Set rDoc = r.Duplicate

    r.Find.ClearFormatting
    Do While bFound
        With r.Find
            .text = "Fedora[0-9][0-9]:[a-z]*[A-Z]*" 
            .Forward = True
            .wrap = wdFindStop
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = True
            .MatchSoundsLike = False
            .MatchAllWordForms = False
            bFound = .Execute
        End With

        If bFound Then
            r.Select
            Selection.EndKey Unit:=wdLine, Extend:=True
        End If
    Loop
End Sub

answered Oct 1, 2018 at 10:06

Cindy Meister's user avatar

Cindy MeisterCindy Meister

24.9k21 gold badges35 silver badges43 bronze badges

Is there a way to find any lines in a Word document then end with a single woes at the end of the visible line?

This example if of one line, and I want to find it in a whole document, as it ends with a single word at the last visible line.
enter image description here
Also, is there a way to find a certain word «minim», given that it shows at the end of the visible line? And ignore it if it shows in the middle of any line?

Thor's user avatar

Thor

6,2941 gold badge35 silver badges42 bronze badges

asked Jan 4, 2019 at 13:33

Mike's user avatar

No, that is not possible.

What you are seeing as a «line» in a document is based on the margin settings of the document and the text dynamically wraps to the next line based on available space. There is not a character in the text line that is forcing the wrap, thus there is nothing that can be searched and found.

Regarding line breaks, MS-Word only allows wildcard searches for words followed by a paragraph character or line feed character.

answered Jan 4, 2019 at 14:47

Rich Michaels's user avatar

Rich MichaelsRich Michaels

2,7962 gold badges10 silver badges20 bronze badges

1

I agree with @rich that this is not technically possible as it depends on the document settings for margins and font sizes, etc., and will be different between computers.

However, if that does not matter to you, you can try to work something out using a macro.

Note that you would have to examine each line (not covered here) until the end of the document.
And also be wary of highlighting only punctuation and repeating steps for a single line if needed.

Selection.HomeKey Unit:=wdStory
Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Copy
' here check for word - make sure to remove punctuation as needed
' continue to next line and repeat
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Copy
' here check for word - make sure to remove punctuation as needed
' you will have to MoveLeft again if you did select punctuation

answered Jan 4, 2019 at 17:00

BlueGI's user avatar

BlueGIBlueGI

2671 silver badge5 bronze badges

2

Quote:

Originally Posted by macropod
View Post

You don’t need a macro for that. All you need is a Find/Replace to change the space after a colon to a non-breaking space. If you do that, only the ones at the line ends will be visibly affected.

Likewise, you don’t need macro to change plain quotes to smart quotes or vice-versa.

…welp, I feel like an idiot now. I didn’t think about using a non-breaking space. And I had been wracking my brain about this for weeks!

My only follow-up concern is that a non-breaking space will work for colons, but not for em-dashes (—) and en-dashes (–), which wouldn’t be followed by a space. Instead, those are followed by words—like this—so I’m not entirely sure how to fix that. My thought was that I’d do a search for the em-dash/en-dash, then move forward a word and replace that word with itself plus a non-breaking space, but I can’t quite get the code to work.

Dim r As Range

Set r = ActiveDocument.Range
With r.Find
Do While .Execute(findtext:=»—», Forward:=True) = True
With r
.Next(unit:=wdWord, Count:=1).Select

With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = «—»
.Replacement.Text = «»
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

With Selection
Dim thatword As String
thatword = Selection.Text
Selection.Find.Replacement.Text = thatword + «^160»

End With
End With
Selection.Find.Execute

Selection.Next(unit:=wdWord, Count:=1).Select

End With
r.Collapse direction:=wdCollapseEnd
Loop
End With

There’s probably a simple error in that code…I just don’t know what it is.

I know that I don’t need to use a macro to change all the quotes because I could just do a find and replace, but since I have to do about a million find and replaces for a ton of different formatting things, I thought it might be easier to just make one big macro to do all of them at once.

The only other line-related thing that I’m completely stumped on is how I can detect when there are one-word lines (like in the example, where the word «utrices» is a single word on a line of its own), so that I can take some words from the previous line to move to that line to make sure no words are alone.

I know there are ways to detect one-word paragraphs, but I don’t know about figuring that out for lines.

Is it even possible?

When we see two lines of words in an MS Word document, we don’t get to see what is separating them. There are severl characters that act as line break. There are several names; line break, new line, carriage return, paragraph break etc.

Today, while doing a bit of data processing, I was required to remove all the line breaks (carriage return) in an MS-Word document and replace line breaks with a comma. I was processing a long list of email addresses with one email address per line. And I wanted this list to become a comma separated list (CSV); so as to use it somewhere else.

In MS-Word, paragraph break is represented by invisible character (¶) which looks like a horizontally flipped P letter. You can toggle the visibility of this character by clicking a button given on the Home tab in MS Word. The button bears the same ¶ symbol. You should click this button to be able to see what exactly is separating the lines.

Our tips on MS-Word make your life easier and increase your productivity at work.

If lines are breaking because of paragraph break then ¶ will appear at the end of the lines. If lines are breaking due to line break (carriage return), a left-angled arrow symbol will appear at the end. Let’s first see how to deal with paragraph break:

How to Remove / Replace Paragraph Break

  • Open the Word document that you want to work on
  • Press CTRL + H to bring up the Find and Replace box
  • In the “Find what” box type ^p [this upward arrow character is called caret and is usually available on a number key]
  • In “Replace with” box type a comma
  • Click on Replace All button.

Thus all the paragraph breaks in you document will get replaced by a comma. You can use whatever character(s) you like in “Replace with” box. For example, if you want to replace every paragraph break with two paragraph breaks –then you should type ^p^p in “Replace with” box.

If you simply want to remove paragraph breaks; just leave the “Replace with” box blank. And you’ll get a monolithic chunk of text!

READ ALSO: How to find ant replace formatting

How to Remove / Replace Line Break, Carriage Return (Enter key)
Follow the same process as given above. Instead of finding paragraph sign (^p), now you should look for line break or carriage return sign (represented by ^l). Therefore, type ^l in “Find what” box and replace it something else (or with nothing).

NOTE: This article is part of my MS Word Guide. This guide solves your day to day MS Word problems. Easily!

So, this is how you can replace line breaks, paragraph breaks and carriage returns in MS Word document. Please le t me know if you have any questions about this topic. I will be glad to try and assist you. Thank you for using TechWelkin.

Featured, Microsoft 365, Microsoft Office, Microsoft Office for Mac, Microsoft Word, Office 2003, Office 2007, Office 2010, Office 2013, Office 2016, Office 2019, Office 365 /

12 August 2021

Word’s Advanced Find has many special codes to help locate or replace hidden or unusual things in a Word document.  Here’s a complete and searchable list of all the ^ codes and what they are for

 Under Find | Advanced Find | More | Special there’s a list of special codes for finding hidden formatting markers.  They are all prefixed with  ^ e.g.  Paragraph mark is  ^p   Tab is ^t  

They’re all listed under the Special button but some (the Wildcard codes) only work for ‘Find what’.

Here’s a complete list of all the special ^ codes used in Word Find and Replace.

We’ve broken them up into categories.

Word special codes – find the hidden marks Word puts in a document for formatting, such as the end of a paragraph or line.

Wildcard – find one or more letters, numbers or symbols when ‘Use Wildcards’ is OFF.  You read that right, the ‘Use Wildcards’ option in Advanced Find really means ‘Use Regular Expressions’.  These codes only work in ‘Find what’, not Replace.

Text symbols – an easy way to find some special symbols instead of hunting down the actual character.  For example use ^+ in find instead of an Em-dash “—”.  Two of these symbols only work in the “Replace with …” field.

Use the Search box (right) or sort the columns to find the code / character you want.

Name Find code Appears in Show All as … Type Comments
Paragraph Mark ^p  Word special codes Word’s way of ending a paragraph.
Tab Mark ^t Word special codes
Any Character ^? Wildcard Any single character, such as a number, letter or symbol.
Any Digit ^# Wildcard Any single number only in the document.
Any Letter ^$ Wildcard Any single letter only in the document.
Caret Character ^^ Text symbols Find the caret (^) symbol, single ^ symbol is used as a prefix for special finds.
Column Break ^n Word special codes Creates a hard break in the inserted location, like a page break or section break, and compels the rest of the content to appear in the next column
Em Dash ^+ Text symbols In a sentence, the Em Dash could be used instead of parentheses, commas, colons, or quotation marks.
En Dash ^= Text symbols A medium-sized dash used to show number and date ranges
Endnote Mark ^e Word special codes Find an Endnote mark that links to a later Endnote.
Field ^d Word special codes Find a Word field. ‘View Fields Codes’ must be on.
Footnote Mark ^f Word special codes The footnote reference mark in the document corresponding a later footnote.
Graphic ^g Word special codes Any image or graphic within the document.
Manual Line Break ^l Word special codes Manual Line break is when the text on the current line is ended, and the text on the next line is continued. Made by typing Shift + Enter
Manual Page Break ^m Word special codes A manual page break can be used to force a new page in your document. Made by typing Ctrl + Enter
Nonbreaking Hyphen ^~ Word special codes Nonbreaking hyphens prevent phrases, hyphenated words, or numbers from breaking towards the end of a line of text.
Nonbreaking Space ^s Word special codes When a line is broken, nonbreaking spaces prevent words or individual characters from separating.
Optional Hyphen ^- Word special codes Controls the hyphenation of words at specific points in the text.
Section Break ^b Word special codes Used to break up a document into sections.
White Space ^w Wildcard Any blank space (normal or non-breaking) and including tabs
Section Character ^% § Text symbols Insert the § symbol.
Used in ‘Replace with’ only.
Paragraph Character ^v Text symbols Insert the ⁋ symbol.
Used in ‘Replace with’ only. It is sometimes referred to as the pilcrow, paragraph sign, paraph, or blind P.

Found! Word shortcut to the Advanced Find dialog
Wildcard Find tricks in Microsoft Word

Понравилась статья? Поделить с друзьями:
  • Word find crossword game
  • Word find colored text
  • Word find color of text
  • Word find capitalized words
  • Word find board games