Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2013, 12:05 AM
macropod's Avatar
macropod macropod is offline Bulletted List Creation Windows 7 32bit Bulletted List Creation Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,536
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


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
Reply With Quote
  #2  
Old 11-10-2013, 09:22 AM
jdean jdean is offline Bulletted List Creation Windows XP Bulletted List Creation Office 2010 32bit
Novice
Bulletted List Creation
 
Join Date: Nov 2013
Posts: 14
jdean is on a distinguished road
Default

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
Reply With Quote
  #3  
Old 11-10-2013, 02:17 PM
macropod's Avatar
macropod macropod is offline Bulletted List Creation Windows 7 32bit Bulletted List Creation Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,536
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 jdean View Post
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?
As I haven't seen the rest of your code, I can't really say whether what you've done is 'correct'. One might just as easily re-name the sub, then Call it from your existing one.
Quote:
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"
Did you adjust the 'Rng' variable to reference Word.Range? Likewise, based on what you've posted so far, you should change 'ActiveDocument' to 'MyDoc'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 11-10-2013, 06:37 PM
jdean jdean is offline Bulletted List Creation Windows XP Bulletted List Creation Office 2010 32bit
Novice
Bulletted List Creation
 
Join Date: Nov 2013
Posts: 14
jdean is on a distinguished road
Default

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
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Calendar Creation sjvjoe Publisher 1 07-14-2016 06:32 PM
Bulletted List Creation 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
Bulletted List Creation Label Creation speloquin Word 1 05-27-2011 03:08 PM
Report creation. Igtech Excel 1 04-02-2010 03:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:15 PM.


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