![]() |
|
|
|
#1
|
||||
|
||||
|
Hard-formatting (i.e. overriding whatever Style is already applied to the content) is poor practice; it can lead to inconsistencies, makes the document harder to manage and introduce corruption. The absence of the required styles in the target documents is easily-enough handled: Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Stl As Style, bBulletA As Boolean, bBulletB As Boolean, Rng As Range
bBulletA = False: bBulletB = False
For Each Stl In ActiveDocument.Styles
If Stl.NameLocal = "BulletA" Then bBulletA = True
If Stl.NameLocal = "BulletB" Then bBulletB = True
Next
If bBulletA = False Then Call AddBulletStyle("BulletA", ChrW(&H25CF))
If bBulletB = False Then Call AddBulletStyle("BulletB", "o")
Set Rng = ActiveDocument.Range
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^13Met[!^13]@^13"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
.Start = .Start + 1
.End = .End - 1
.Style = "BulletA"
.Collapse wdCollapseEnd
.Find.Execute
Loop
.Start = Rng.Start
.End = Rng.End
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^13Exceeded[!^13]@^13"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
.Start = .Start + 1
.End = .End - 1
.Style = "BulletB"
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
End Sub
Private Sub AddBulletStyle(StrNm As String, StrBullet As String)
Dim Stl As Style
Set Stl = ActiveDocument.Styles.Add(Name:=StrNm, _
Type:=wdStyleTypeParagraph)
With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
.NumberFormat = StrBullet
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(1)
.TabPosition = InchesToPoints(1)
.ResetOnHigher = 0
.StartAt = 1
.LinkedStyle = StrNm
End With
With Stl
.AutomaticallyUpdate = False
.BaseStyle = "Normal"
.LinkToListTemplate _
ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(1), _
ListLevelNumber:=1
With .ParagraphFormat
.LeftIndent = InchesToPoints(1)
.RightIndent = InchesToPoints(0)
.FirstLineIndent = InchesToPoints(-1)
.TabStops.ClearAll
.TabStops.Add Position:=InchesToPoints(1), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
End With
End With
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 11-10-2013 at 12:08 AM. Reason: Code revision |
|
#2
|
|||
|
|||
|
Macropod, I copied Private Sub AddBulletStyle and placed it in the "General Section" of the module as I would for a function. I then copied Sub Demo into my code. Is this correct?
However, when I compiled, I got a compiler in Sub Demo code, that highlights the last ".End" in the line .End = Rng.End and says, "Argument not optional" Thanks! Jay |
|
#3
|
||||
|
||||
|
Quote:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#4
|
|||
|
|||
|
Macropod,
I followed your suggestions by qualifying the rng object, activedocument etc., ran it and I'm happy to say it is getting very close to what I want. However, I must admit I don't think I made my requirements quite clear enough in the beginning but I think if you can re-tweak the code slightly to meet the following conditions I will be good. 1. If the first word of a paragraph is "Drafted" do Nothing. Don't touch the paragraph. 2. If (the first word of a paragraph IS NOT "Drafted") and (the first word of the same paragraph IS NOT "Exceeded") then apply the bullet ChrW(61623). **NOTE: Bullet should be on/or closest to page margin but distance between the bullet and the paragraph should be about 0.5 inch. Also, the paragraph font.bold = true 3. If the first word of a paragraph is "Exceeded" then apply the hollow circle bullet "O" . NOTE**: Bullet should be 1 inch from page margin but distance between the bullet and the paragraph should be about 0.5 inch. Also the paragraph font.bold = false 4. In any case do not change the current paragraph.spacesafter or spacebefore setting between any two paragrapghs Thanks in advance. This is so close! Jay Last edited by jdean; 11-10-2013 at 06:39 PM. Reason: correction |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Calendar Creation | sjvjoe | Publisher | 1 | 07-14-2016 06:32 PM |
Document Creation
|
Privateer | Word | 3 | 06-20-2013 08:15 PM |
| Help with Complex Table Creation | saquib | Word | 0 | 02-12-2013 06:28 AM |
Label Creation
|
speloquin | Word | 1 | 05-27-2011 03:08 PM |
| Report creation. | Igtech | Excel | 1 | 04-02-2010 03:33 PM |