Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-03-2018, 02:04 PM
MauiTruss MauiTruss is offline Macro to select multiple sentences that contain a specific word Windows 7 64bit Macro to select multiple sentences that contain a specific word Office 2016
Novice
Macro to select multiple sentences that contain a specific word
 
Join Date: Oct 2018
Posts: 4
MauiTruss is on a distinguished road
Default Macro to select multiple sentences that contain a specific word

I am looking to create a macro that will select a line that contains a specific word. Ideally it would select all the occurrences in the whole document at once. The word would always be the same so no need for a prompt. I got started but am not sure if I a headed in the right direction. I am pretty lost when it comes to VBA. Any help would be greatly appreciated.

Sub AdjustText()
'
' AdjustText Macro
'
'
Dim myRange As Range
Set myRange = ActiveDocument.Range


With myRange.Find
.text = "Word"
.Replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
If .Found Then
Selection.Extend
Selection.Extend
Selection.Extend
End If
End With
End Sub
Reply With Quote
  #2  
Old 10-03-2018, 02:55 PM
macropod's Avatar
macropod macropod is offline Macro to select multiple sentences that contain a specific word Windows 7 64bit Macro to select multiple sentences that contain a specific word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The correct way to encode such a macro (if one is needed at all) depends on what you mean by "select a line that contains a specific word", which is different from your thread title that mentions sentences. Do those lines constitute an entire paragraph? Alternatively, are the lines terminated by manual line breaks? Do you want both ends of the 'line' included? Then there is the question of what you actually want to do with these lines?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-03-2018, 03:04 PM
MauiTruss MauiTruss is offline Macro to select multiple sentences that contain a specific word Windows 7 64bit Macro to select multiple sentences that contain a specific word Office 2016
Novice
Macro to select multiple sentences that contain a specific word
 
Join Date: Oct 2018
Posts: 4
MauiTruss is on a distinguished road
Default

I am looking to select the entire line. Using the word sentence in the title was misleading.

Yes the lines constitute an entire paragraph.

The lines are terminated by manual line breaks.

I would like both ends of the line included.

Once selected I would be making changes font and other text formatting.
Reply With Quote
  #4  
Old 10-03-2018, 03:11 PM
macropod's Avatar
macropod macropod is offline Macro to select multiple sentences that contain a specific word Windows 7 64bit Macro to select multiple sentences that contain a specific word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by MauiTruss View Post
Yes the lines constitute an entire paragraph.

The lines are terminated by manual line breaks.
These two statements are inconsistent. Please clarify. With Word's formatting display turned on, are these lines preceded by ¶, or by ↵?
Quote:
Originally Posted by MauiTruss View Post
Once selected I would be making changes font and other text formatting.
Without knowing what those changes are (which quite possibly should be applied via a paragraph Style, it's impossible to write the required macro, since macros process such content iteratively, not concurrently.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 10-03-2018, 03:23 PM
MauiTruss MauiTruss is offline Macro to select multiple sentences that contain a specific word Windows 7 64bit Macro to select multiple sentences that contain a specific word Office 2016
Novice
Macro to select multiple sentences that contain a specific word
 
Join Date: Oct 2018
Posts: 4
MauiTruss is on a distinguished road
Default

the line is preceded by ¶. Sorry for the confusion.

I will be changing the font size.
Reply With Quote
  #6  
Old 10-03-2018, 03:26 PM
macropod's Avatar
macropod macropod is offline Macro to select multiple sentences that contain a specific word Windows 7 64bit Macro to select multiple sentences that contain a specific word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In that case you should create a paragraph Style with the attributes you require and apply that. The Style can be applied quite easily via a wildcard Find/Replace, where:
Find = Word*^13
Replace = ^&
and you specify the Style as a replacement parameter. No macros required.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 10-03-2018, 03:41 PM
MauiTruss MauiTruss is offline Macro to select multiple sentences that contain a specific word Windows 7 64bit Macro to select multiple sentences that contain a specific word Office 2016
Novice
Macro to select multiple sentences that contain a specific word
 
Join Date: Oct 2018
Posts: 4
MauiTruss is on a distinguished road
Default

I would want to change the font size of the entire line that contains the word. Not just the individual word.

The word document is generated automatically from another program. I have no ability to control the paragraph style or formatting. Just trying to increase the text size of specific lines to be larger and have the whole multi page document done all at once.
Reply With Quote
  #8  
Old 10-03-2018, 03:46 PM
macropod's Avatar
macropod macropod is offline Macro to select multiple sentences that contain a specific word Windows 7 64bit Macro to select multiple sentences that contain a specific word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by MauiTruss View Post
I would want to change the font size of the entire line that contains the word. Not just the individual word.
As I said, you can do that via a paragraph Style. You clearly didn't try the wildcard Find/Replace I suggested; otherwise you'd know that by now.
Quote:
Originally Posted by MauiTruss View Post
The word document is generated automatically from another program. I have no ability to control the paragraph style or formatting. Just trying to increase the text size of specific lines to be larger and have the whole multi page document done all at once.
It makes no difference what the document's origin is if you add the Style to it via the Organizer.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to select multiple sentences that contain a specific word Macro to number sentences tjf816 Word VBA 10 03-29-2017 05:42 PM
Macro to select multiple sentences that contain a specific word Macro to insert multiple pictures to word to a specific size and text wrap mescaL Word VBA 3 11-03-2014 10:51 PM
Macro to select multiple sentences that contain a specific word Cannot select single characters. Word selects paragraphs or parts of sentences. TMinnich Word 2 10-25-2013 09:38 AM
Macro to select multiple sentences that contain a specific word Need a Macro that Combines Every 5 sentences into a paragraph jgarland Word 22 01-11-2012 11:19 AM
Select multiple value on Word 2003/2007 forms dzn Word 0 07-19-2010 01:56 AM

Other Forums: Access Forums

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


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