#1
|
|||
|
|||
Macro set Right Tab
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 |
#2
|
|||
|
|||
Just add the following immediately before that line:
Code:
Dim myRange as Range |
#3
|
|||
|
|||
Hi, thank you but that didn't work for me when I tried before posting.
Not sure why? Regards jec |
#4
|
|||
|
|||
Hi, the macro just doesn't work as it says - it doesn't do anything. No errors but not working.
Thank you again. Regards jec |
#5
|
|||
|
|||
The code does exactly what it says it does in the explanatory comments, adds a right tab-stop to the selected paragraphs. You won't see anything unless the text that you are applying it to contains tab characters.
What are you expecting it to do? |
#6
|
|||
|
|||
Rather than a macro, why not use the tools that come with Word. Use a style that has your tab setting.
|
#7
|
|||
|
|||
All good everyone (blonde moment) - I was sitting there waiting for the line to insert itself as well.... (what can I say) a long week.
But tks. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to Remove Paras with Line Spac 6; Macro to Convert Paragraphs to Outline Numbered | venganewt | Word VBA | 0 | 01-25-2022 06:28 PM |
Calling macro from loop-all-files macro only opens one file | Peterson | Word VBA | 0 | 03-27-2021 07:58 PM |
Spell check macro within macro button field doesn't work in one document | samuelle | Word VBA | 0 | 07-20-2016 02:27 AM |
Macro Needed to bold specific lines and Macro to turn into CSV | anewteacher | Word VBA | 1 | 05-28-2014 03:59 PM |
custom icon, undo/redo for macro, permanent macro | Rapier | Excel | 0 | 08-05-2013 06:30 AM |