Macro for right flush dot leader tab

M

Mary Lou in PA

When I create this macro it works, however anytime I tab after the macro has
played all the tabs are now right flush dot leader.

Am I missing a step somewhere?

Thanks
 
M

Mary Lou in PA

I used record macro, then followed all steps that I did in previous version
of word to get the dot leader with right justified. Then stop recording. Is
that incorrect?

If so what should I do? Thanks
 
S

Stefan Blom

Which version of Word are you using? Note that the macro recorder may give
different results in different versions of Word.

In Word 2007, when I record adding a right-aligned tab stop with a dot
leader I certainly get code that can be run, though. For example:

Sub TestingCreateTabStop()
Selection.ParagraphFormat.TabStops.Add _
Position:=InchesToPoints(2), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderDots
End Sub

Please post your code. You could just copy it from the Visual Basic Editor
(which you can display by pressing Alt+F11).
 
M

Mary Lou in PA

We are using Word 2007, and I think I copy/pasted the code correctly. Hope
this helps. Thanks



Sub Dotleader()
'
' Dotleader Macro
'
'
Selection.Font.Bold = wdToggle
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphJustify
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
Selection.ParagraphFormat.TabStops.ClearAll
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(6.75), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderDots
Selection.TypeText Text:=vbTab
End Sub
 
S

Stefan Blom

Mary Lou in PA said:
We are using Word 2007, and I think I copy/pasted the code correctly.
Hope
this helps. Thanks



Sub Dotleader()
'
' Dotleader Macro
'
'
Selection.Font.Bold = wdToggle
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphJustify
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With

These lines of code are irrelevant for setting tab stops. As you may know,
this is a common side-effect of the macro recorder.
Selection.ParagraphFormat.TabStops.ClearAll
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(6.75),
_
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderDots
Selection.TypeText Text:=vbTab
End Sub

The code above clears all existing tab stops, then sets a value for the
default tab stops. A custom tab stop is added at 6.75" from the left margin,
and the type is set to right-aligned with a dot leader. Finally, a tab
character is added. This seems pretty much what I found when I tested this.
In what way does this code fail for you?

--
Stefan Blom
Microsoft Word MVP
 
M

Mary Lou in PA

WHen I did this, after I close the macro, and use it once it is OK. then if
I continue down a couple lines and hit a normal tab it acts like the dot
leader right aligned tab. I need the macro to end and then let me go back to
defaulted normal tabs.
 
S

Stefan Blom

If you "continue down" by pressing Enter, the tab stop formatting will be
carried over to the new paragraphs created. The same thing happens when you
manually apply formatting to text.

If you want to clear the tab stops for the selection, just use:

Selection.ParagraphFormat.TabStops.ClearAll

in a different macro.

Note that you may find it easier to change the formatting by applying the
proper styles to text instead.
 
M

Mary Lou in PA

OK, that is what we have done, created an additional macro to clear the
previously formatted tabs. It was different in our previous version of Word
and we were trying to avoid this second step. Thanks
 

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