Thank you for the help, that worked.
Can I ask a related “Heading” question? I have the following macro that lets
me inserts a $ at the beginning of a Heading if my cursor is in that Heading.
This macro works fine, but is there a better way to write it?.
Dim textbox As Shape
If Selection.Style = ActiveDocument.Styles("Heading 1") Then
With ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 35, _
Selection.Information(wdVerticalPositionRelativeToPage) - 5, 22, 24)
With .TextFrame.TextRange
.Text = "$"
.Font.Size = 14
End With
.Fill.Visible = msoFalse
.Line.Visible = msoFalse
End With
Else
If Selection.Style = ActiveDocument.Styles("Heading 2") Then
With ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 35, _
Selection.Information(wdVerticalPositionRelativeToPage) - 5, 22, 24)
With .TextFrame.TextRange
.Text = "$"
.Font.Size = 14
End With
.Fill.Visible = msoFalse
.Line.Visible = msoFalse
End With
Else
If Selection.Style = ActiveDocument.Styles("Heading 3") Then
‘and so on...
> You could also do 4 ReplaceAll (one for each paragraph style):
> ..Style = ActiveDocument.Styles(wdStyleHeading1)
[quoted text clipped - 11 lines]
> Regards,
> Klaus
Klaus Linke - 17 Mar 2007 18:35 GMT
Your code looks just fine... Grasping for some criticism, maybe a Select
Case would be easier to read:
Select Case Selection.Style
Case ActiveDocument.Styles(wdStyleHeading1),
ActiveDocument.Styles(wdStyleHeading1)
' ...
Case ActiveDocument.Styles(wdStyleHeading3)
' ...
Regards,
Klaus
> Thank you for the help, that worked.
>
[quoted text clipped - 50 lines]
>> Regards,
>> Klaus
LEU - 17 Mar 2007 21:42 GMT
Thank you for the input Klaus. I'm new to writing macros and sense I don't
know all the VB language I sometimes feel I’m taking the long way to get a
macro written.
Thanks again.
LEU
> Your code looks just fine... Grasping for some criticism, maybe a Select
> Case would be easier to read:
[quoted text clipped - 63 lines]
> >> Regards,
> >> Klaus