Apply Bold to words/characters that have manually been formattedbold, skipping certain styles

A

andreas

Dear Experts:

I would like to achieve the following using VBA:

Apply Bold with a user-defined character style (Char_Style_Bold) to
all characters/words that have been formatted bold manually,
.... skipping paragraphs where the applied paragraph style has a bold
setting as well as
.... skipping words/characters where a previous applied character style
(also) has a bold setting

May sound strange, but I hope I have made myself clear. I wonder
whether this is possible?

Help is much appreciated. Thank you very much in advance.

Regards,

Andreas
 
S

Shasur

Hi Andreas

Here is a glimmer

Sub Find_Replace_BOLD_Style()

Dim FindChar
Dim ReplaceChar
Dim rngStory As Range


Selection.HomeKey wdStory, wdMove
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Format = True
Selection.Find.Font.Bold = True
Selection.Find.Execute FindText:=""
Do While Selection.Find.Found = True
If Selection.Style = "Normal" Then
Selection.Style = "Char_Style_Bold"
End If
Selection.MoveRight
Selection.Find.Execute FindText:=""
Loop


End Sub

Cheers
Shasur
 
H

Helmut Weber

Hi Andreas,

if I got you right,
all you need is this:

Sub TestTab()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Font.Bold = True
While .Execute
If rDcm.Style.Font.Bold <> -1 Then
' rDcm.Select
' rdcm.Style = YourStyle
End If
Wend
End With
End Sub

You can adapt the commented lines yourself, I think.
 
A

andreas

...improved:

Sub TestTab()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
   .Font.Bold = True
   While .Execute
      If rDcm.Style.Font.Bold <> -1 Then
         ' rDcm.Select
         rDcm.Style = "Zch02"
         rDcm.Collapse direction:=wdCollapseEnd
      End If
   Wend
End With
End Sub

Otherwise is works only for the first found spot.

Helmut,

admit it, you are a genius! Terrific Help. Very few lines, very fast,
your coding. Exactly what I wanted.

Thank you very much. Regards, Andreas
 
A

andreas

Hi Andreas

Here is a glimmer

Sub Find_Replace_BOLD_Style()

Dim FindChar
Dim ReplaceChar
Dim rngStory As Range

Selection.HomeKey wdStory, wdMove
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Format = True
Selection.Find.Font.Bold = True
Selection.Find.Execute FindText:=""
Do While Selection.Find.Found = True
    If Selection.Style = "Normal" Then
        Selection.Style = "Char_Style_Bold"
    End If
    Selection.MoveRight
    Selection.Find.Execute FindText:=""
Loop

End Sub

Cheers
Shasur
--http://vbadud.blogspot.com









- Zitierten Text anzeigen -

Hey Sashur,

thank you very much for your help. Your code is working fine, too.
Great help, although I have to admit that for my special purpose,
Helmut's code is a bit better.

Again, thank you for your working code.

Regards, Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top