Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace string with formatted bullet in word

Status
Not open for further replies.
Sep 16, 2009
15
CA
I'm using an excel macro to find/replace a string with a formatted bullet in word. The code I'm using inserts a symbol and the formatting does not apply (i.e., the bulleted text does not allign with an indent). I need an actual bullet. Any ideas?

Code:
wdAPP.Selection.Find.ClearFormatting
wdAPP.Selection.Find.Replacement.ClearFormatting
With wdAPP.Selection.Find
    .Text = "sbullet2"
    With .Replacement
    .ClearFormatting
    .Text = ChrW(61558) & vbTab
    .Font.Name = "Wingdings"
    .Font.Color = wdBlack
    End With
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = True
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
wdAPP.Selection.Find.Execute Replace:=wdReplaceAll
 
hi,

Please explain EXACTLY what you mean by
the bulleted text does not allign with an indent
Could you post an ACTUAL example of the TEXT in your document that exists BEFORE and AFTER one of the FIND STRINGS, prior to running your macro.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
What I mean is, my code adds a bullet as a symbol, not actual bulleting format, the second line does not indent because it's not actually a bullet.

Before:

sbullet2This is the string of text that is replacing the string ”sbullet2”. “sbullet2” is actually a place holder that I entered from a previous find/replace entry.

After:

 This is the string of text that is replacing the string ”sbullet2”. “sbullet2” is actually a place holder that I entered from a previous find/replace entry.

In the after, I want all of the text to be bulleted. The "a previous ..." should be alligned with the "This is the string...
 
Correction:

The 'after' example above didn't wrap as it did in my preview. I meant to illustrate that the subsequent lines do not indent correctly as shown here:

This is the string of text that is replacing the string ”sbullet2”. “sbullet2” is actually a place holder that I entered from a previous find/replace entry. This is the string of text that is replacing the string ”sbullet2”. “sbullet2” is actually a place holder that I entered from a previous find/replace entry.



 
3rd try:

 This is the string of text that is replacing the string ”sbullet2”. “sbullet2” is actually a place holder that I entered from a previous find/replace entry. This is the string of text that is replacing the string ”sbullet2”. “sbullet2” is actually a place holder that I entered from a previous find/replace entry.


 
Here is and example of the BEORE and AFTER texts I was looking for as it exists prior to running the macro
Code:
Now is the time
sbullet2 other stuff
sbullet2 more stuff
for all good men
sbullet2 no tab
sbullet2 nada
sbullet2 some other
to come to the aid of their country
Now I run your macro and here is the subsequent result
Code:
Now is the time
      other stuff
      more stuff
for all good men
      no tab
      nada
      some other
to come to the aid of their country
Of course the  character IS a WINGDING in my document.

Do you not get a similar result?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Exactly. However, if the text is longer than one row, it will wrap but does not allign with the row above.

Code:
Now is the time
      other stuff blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah 
      more stuff
for all good men
      no tab
      nada
      some other
to come to the aid of their country
 
Well, you never even mentioned that!

That is simply an adjustement of the hanging indent!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I tried replaceing vbtab with "^t" but it did not work. How do I adjust it.
 
I tried replaceing vbtab with "^t"
is like saying, "I replaced 'X' with 'X'!"

I am referring to the Hanging Indent associated with a paragraph, using the Hanging Indent ICON in the Ruler. Actually there are several ways to address this like First Line Indent or Hanging Indent. But it is all associated with properties of a Paragraph.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
try something like this AFTER you replace...
Code:
    Dim ph As Word.Paragraph
    
    For Each ph In wdAPP.ActiveDocument.Paragraphs
        With ph
            If .Range.Characters(1) = ChrW(61558) Then
                .Range.Select
                With wdAPP.Selection.ParagraphFormat
                    .LeftIndent = InchesToPoints(0.5)
                    .RightIndent = InchesToPoints(0)
                    .SpaceBefore = 0
                    .SpaceBeforeAuto = False
                    .SpaceAfter = 10
                    .SpaceAfterAuto = False
                    .LineSpacingRule = wdLineSpaceMultiple
                    .LineSpacing = LinesToPoints(1.15)
                    .Alignment = wdAlignParagraphLeft
                    .WidowControl = True
                    .KeepWithNext = False
                    .KeepTogether = False
                    .PageBreakBefore = False
                    .NoLineNumber = False
                    .Hyphenation = True
                    .FirstLineIndent = InchesToPoints(-0.5)
                    .OutlineLevel = wdOutlineLevelBodyText
                    .CharacterUnitLeftIndent = 0
                    .CharacterUnitRightIndent = 0
                    .CharacterUnitFirstLineIndent = 0
                    .LineUnitBefore = 0
                    .LineUnitAfter = 0
                    .MirrorIndents = False
                    .TextboxTightWrap = wdTightNone
                End With
            End If
        End With
    Next

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Great suggestion.

I just needed to add "text" to:

Code:
If .Range.Characters(1).text = ChrW(61558) Then

and the following two gave errors so I removed them:

Code:
.MirrorIndents = False
.TextboxTightWrap = wdTightNone

but otherwise it is working perfectly.
Thanks!
 
You will need to LOOK UP in HELP, all WORD CONSTANTS and replace with actual values, like wdTightNone is 0 (ZERO).

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
IMHO, it would be far better to define a suitable bulleted Paragraph Style, then use a wildcard Find/Replace to delete the 'ChrW(61558) & vbTab' strings and apply the Paragraph Style. Hard-formatting paragraphs is rarely a good idea. Having a Style also makes the document far easier to mainatin.

Cheers
Paul Edstein
[MS MVP - Word]
 
I yield to a Master!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top