Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-31-2015, 08:39 AM
AustinBrister AustinBrister is offline VBA to set format for paragraphs that meet with specific requirements Windows 7 64bit VBA to set format for paragraphs that meet with specific requirements Office 2013
Novice
VBA to set format for paragraphs that meet with specific requirements
 
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 VBA to set format for paragraphs that meet with specific requirements Windows 7 32bit VBA to set format for paragraphs that meet with specific requirements Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
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 VBA to set format for paragraphs that meet with specific requirements Windows 7 64bit VBA to set format for paragraphs that meet with specific requirements Office 2013
Novice
VBA to set format for paragraphs that meet with specific requirements
 
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 VBA to set format for paragraphs that meet with specific requirements Windows 7 64bit VBA to set format for paragraphs that meet with specific requirements Office 2013
Novice
VBA to set format for paragraphs that meet with specific requirements
 
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



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to set format for paragraphs that meet with specific requirements 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
VBA to set format for paragraphs that meet with specific requirements Exporting from excel into a specific format Bambi555 Excel 2 09-22-2014 08:08 AM
VBA to set format for paragraphs that meet with specific requirements Inputting a number into word in a specific format Jo 4x4 Word 7 07-19-2014 12:45 AM
VBA to set format for paragraphs that meet with specific requirements 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:00 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