Hi all, getting a variable not defined error but can't resolve it! Out of practise.
Code:
Sub RightTab()
'The macro will work even if the selected paragraphs have differing right margins from
'each other. It also takes into account your current page setup.
'
'If you don't want the macro to remove all the tab stops already set in the selected
'paragraphs, remove the line that uses the ClearAll method.
'If you want to use dot leaders on the tab instead of underscores,
'then change the wdTabLeaderLines constant name to wdTabLeaderDots.
'
'If you set quite a few such tabs, you may be interested in the RightTab VBA macro
'shown below. When run, it examines each paragraph you have selected, clears all their 'tab stops, and sets a single right tab at the right margin with an underscore leader.
Dim MarPos As Integer, NewPos As Integer
Dim ThisPar As Paragraph
MarPos = Selection.PageSetup.PageWidth - _
Selection.PageSetup.LeftMargin - _
Selection.PageSetup.RightMargin - _
Selection.PageSetup.Gutter
Set myRange = Selection.Range 'Variable not defined
For Each ThisPar In myRange.Paragraphs
NewPos = MarPos - ThisPar.RightIndent
ThisPar.TabStops.ClearAll
ThisPar.TabStops.Add Position:=NewPos, _
Alignment:=wdAlignTabRight, _
Leader:=wdTabLeaderLines
Next ThisPar
End Sub
Many tks jec