Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 05-31-2015, 08:39 AM
AustinBrister AustinBrister is offline Windows 7 64bit Office 2013
Novice
 
Join Date: May 2015
Posts: 16
AustinBrister is on a distinguished road
Default VBA to set format for paragraphs that meet with specific requirements

I need a VBA that will go through all the selected text, and nothing more, and analyze each paragraph, then set each of those paragraphs that match ANY of the following conditions, to the style "Quote":
  1. Begins with " and contains no other " within the paragraph
  2. Begins with " AND ends with " AND there are no other " within the paragraph
  3. is already indented at least 0.4" or more on the left and 0.4" or more on the right



Any tips?

Thanks in advance!
Reply With Quote
  #2  
Old 05-31-2015, 12:57 PM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 741
gmaxey will become famous soon enough
Default

Austin,

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oPar As Paragraph
Dim bStyle As Boolean
Dim oRng As Word.Range
  For Each oPar In Selection.Paragraphs
    bStyle = False
    Select Case True
      Case oPar.LeftIndent > 0.4 And oPar.RightIndent > 0.4: bStyle = True
      Case Asc(oPar.Range.Characters.First) = 34
        Set oRng = oPar.Range
        oRng.Start = oRng.Start + 1
        If InStr(oRng.Text, Chr(34)) = 0 Then
          bStyle = True
        ElseIf InStr(oRng.Text, Chr(34)) = Len(oRng.Text) - 1 Then
          bStyle = True
        End If
      Case Else
        'Do nothing
    End Select
    If bStyle Then oPar.Range.Style = "Quote"
  Next oPar
lbl_Exit:
  Exit Sub
End Sub
There is an old saw that goes "Give a man a fish and he eats for a day. Teach a man to fish and he eats for a lifetime." I realize that you are a novice and I've been giving you several fish. The the process here should be that you first try on your own. If you can't work it out then post your attempt and then ask for assistance. Fair enough?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 06-01-2015, 06:52 AM
AustinBrister AustinBrister is offline Windows 7 64bit Office 2013
Novice
 
Join Date: May 2015
Posts: 16
AustinBrister is on a distinguished road
Default

Thank you so much again! You're so good at this, I appreciate it big time.
Reply With Quote
  #4  
Old 06-01-2015, 07:00 AM
AustinBrister AustinBrister is offline Windows 7 64bit Office 2013
Novice
 
Join Date: May 2015
Posts: 16
AustinBrister is on a distinguished road
Default

I'll start posting my attempts. Thanks again for the help.
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to Insert text into the beginning on specific paragraphs unless the paragraph is blank caboy Word VBA 2 04-01-2015 07:00 AM
Exporting from excel into a specific format Bambi555 Excel 2 09-22-2014 08:08 AM
Inputting a number into word in a specific format Jo 4x4 Word 7 07-19-2014 12:45 AM
Applying specific format to doc jrodriguez Word 3 07-23-2012 08:38 PM
How to count cells containing data and meet certain criteria AdamNT Excel 1 08-11-2006 11:51 PM


All times are GMT -7. The time now is 06:59 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft