Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-24-2018, 09:21 AM
phreaddy phreaddy is offline Reformat a paragraph that starts with certain words Windows 10 Reformat a paragraph that starts with certain words Office 2016
Novice
Reformat a paragraph that starts with certain words
 
Join Date: Apr 2018
Posts: 2
phreaddy is on a distinguished road
Default Reformat a paragraph that starts with certain words

Hi, all,



Using Word 2016/365, my team and I write about 50 monthly reports with headings that always start with the day, month and date, like "Monday, January 1." That's the whole paragraph.

Anyone know how I could code VBA to, for example, take every paragraph that starts with a day of the week, then turn the whole paragraph bold and turn on the "keep with next" feature? I could probably figure out the formatting by recording a macro formatting text, and seeing the code that it came up with. But I can't figure out the VBA for searching for days of the week at the start of a paragraph.

TIA for any help!

Phreaddy
Reply With Quote
  #2  
Old 04-24-2018, 04:38 PM
eduzs eduzs is offline Reformat a paragraph that starts with certain words Windows 10 Reformat a paragraph that starts with certain words Office 2010 32bit
Expert
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

You can start with something like that:

Backup your files before test, test before use, use at your own

Code:
Sub test()
Dim MyPara As Paragraph
For Each MyPara In ActiveDocument.Paragraphs
    If Left(MyPara.Range.Text, 6) = "Friday" Then
        MyPara.Range.Font.Bold = True
        MyPara.Range.ParagraphFormat.KeepWithNext = True
    End If
Next

End Sub
__________________
Backup your original file before doing any modification.
Reply With Quote
  #3  
Old 04-24-2018, 04:53 PM
Guessed's Avatar
Guessed Guessed is offline Reformat a paragraph that starts with certain words Windows 10 Reformat a paragraph that starts with certain words Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I would use a variation on eduzs code and make use of styles which typically have the bold and keep with next settings
Code:
Sub test()
  Dim MyPara As Paragraph
  For Each MyPara In ActiveDocument.Paragraphs
    Select Case Trim(MyPara.Range.Words.First)
      Case "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
        MyPara.Style = "Heading 1"
    End Select
  Next
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 04-25-2018, 06:24 AM
phreaddy phreaddy is offline Reformat a paragraph that starts with certain words Windows 10 Reformat a paragraph that starts with certain words Office 2016
Novice
Reformat a paragraph that starts with certain words
 
Join Date: Apr 2018
Posts: 2
phreaddy is on a distinguished road
Default

Thanks, guys. You rock.
Reply With Quote
  #5  
Old 04-25-2018, 02:50 PM
macropod's Avatar
macropod macropod is offline Reformat a paragraph that starts with certain words Windows 7 64bit Reformat a paragraph that starts with certain words Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Cross-posted at: http://www.vbaexpress.com/forum/show...-certain-words
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Reformat a paragraph that starts with certain words Find a sentence that starts with certain words and change the style MAHE Word VBA 2 02-26-2018 08:40 AM
Can I have 2 styles in one paragraph in order to populate a TOC with the first words only? mlkmnsgrl Word 6 01-01-2015 10:44 AM
Adding All Non-spelling Words in a Paragraph to Dictionary SQLUSA Word 5 07-13-2012 04:05 AM
reformat file renato Word 1 06-13-2012 06:32 AM
Huge spaces between words in a justified paragraph! techdaemon Word 2 02-22-2010 12:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:21 PM.


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