Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-29-2022, 01:52 AM
jec1 jec1 is offline Macro set Right Tab Windows 10 Macro set Right Tab Office 2019
Advanced Beginner
Macro set Right Tab
 
Join Date: Jan 2012
Posts: 84
jec1 is on a distinguished road
Default 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
Many tks jec
Reply With Quote
  #2  
Old 04-29-2022, 03:16 AM
Italophile Italophile is offline Macro set Right Tab Windows 11 Macro set Right Tab Office 2021
Expert
 
Join Date: Mar 2022
Posts: 334
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Just add the following immediately before that line:

Code:
Dim myRange as Range
Reply With Quote
  #3  
Old 04-29-2022, 03:38 PM
jec1 jec1 is offline Macro set Right Tab Windows 10 Macro set Right Tab Office 2019
Advanced Beginner
Macro set Right Tab
 
Join Date: Jan 2012
Posts: 84
jec1 is on a distinguished road
Default

Hi, thank you but that didn't work for me when I tried before posting.
Not sure why?

Regards
jec
Reply With Quote
  #4  
Old 04-29-2022, 03:42 PM
jec1 jec1 is offline Macro set Right Tab Windows 10 Macro set Right Tab Office 2019
Advanced Beginner
Macro set Right Tab
 
Join Date: Jan 2012
Posts: 84
jec1 is on a distinguished road
Default

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
Reply With Quote
  #5  
Old 04-30-2022, 03:51 AM
Italophile Italophile is offline Macro set Right Tab Windows 11 Macro set Right Tab Office 2021
Expert
 
Join Date: Mar 2022
Posts: 334
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

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?
Reply With Quote
  #6  
Old 04-30-2022, 09:28 AM
Charles Kenyon Charles Kenyon is offline Macro set Right Tab Windows 10 Macro set Right Tab Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Rather than a macro, why not use the tools that come with Word. Use a style that has your tab setting.
Reply With Quote
  #7  
Old 05-02-2022, 02:14 AM
jec1 jec1 is offline Macro set Right Tab Windows 10 Macro set Right Tab Office 2019
Advanced Beginner
Macro set Right Tab
 
Join Date: Jan 2012
Posts: 84
jec1 is on a distinguished road
Default

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.
Reply With Quote
Reply



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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft