Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Tab stop weirdness

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick Charnes - 25 Oct 2005 18:06 GMT
In my macro I want to clear all tabs, then set two tabs which should be
active for any text that the macro pumps out in the rest of the
document.  I use this code from a 'Record Macro':

'set tab stops only at 1.25" and 3.0"
Selection.ParagraphFormat.TabStops.ClearAll
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(1.25), _
    Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(3), _
    Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces

But for some reason after this code is executed these two tabs only hold
for the first paragraph of text that is pumped out afterwards.  After
that, the tab setting reverts to one tab every 0.5".  What am I doing
wrong?  Thanks.
Anne Troy - 25 Oct 2005 18:37 GMT
Rick, I think it would be a lot easier for you to create a style, and apply
that style to the rest of the document.
I believe you could record yourself creating a style.
http://www.officearticles.com/word/create_a_style_in_microsoft_word.htm
************
Anne Troy
www.OfficeArticles.com

> In my macro I want to clear all tabs, then set two tabs which should be
> active for any text that the macro pumps out in the rest of the
[quoted text clipped - 12 lines]
> that, the tab setting reverts to one tab every 0.5".  What am I doing
> wrong?  Thanks.
Rick Charnes - 25 Oct 2005 19:22 GMT
Thanks, I'll take a look at this.  In the meantime, can you think of why
my code would not be working?  Thanks much.

> Rick, I think it would be a lot easier for you to create a style, and apply
> that style to the rest of the document.
[quoted text clipped - 20 lines]
> > that, the tab setting reverts to one tab every 0.5".  What am I doing
> > wrong?  Thanks.
Doug Robbins - Word MVP - 25 Oct 2005 21:21 GMT
You would have to reveal how your macro is "pumping out the rest of the
document."

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Thanks, I'll take a look at this.  In the meantime, can you think of why
> my code would not be working?  Thanks much.
[quoted text clipped - 26 lines]
>> > that, the tab setting reverts to one tab every 0.5".  What am I doing
>> > wrong?  Thanks.
Rick Charnes - 25 Oct 2005 21:31 GMT
Oh brother -- I figured out what I was doing wrong.  Thanks for all the
help.

> You would have to reveal how your macro is "pumping out the rest of the
> document."
Rick Charnes - 25 Oct 2005 21:40 GMT
> You would have to reveal how your macro is "pumping out the rest of the
> document."

Yup, I realized that my text is already below where I am.  So I need to:

(1) Select text from current position to end-of-document
(2) Set new tab stops
(3) Turn off selection and return to original position before (1)

I assume I do the step (1) with:
Selection.EndKey Unit:=wdStory, Extend:=wdExtend

But I'm not sure how to turn off the selection and return to my original
position.  Any thoughts?  Thanks much.
Ed - 25 Oct 2005 21:59 GMT
You might try setting a Range and doing everything in that.
Dim rngWork As Range
Set rngWork = ActiveDocument.Range(Selection.Range.Start,
ActiveDocument.Content.End)
With rngWork.ParagraphFormat.TabStops
  .ClearAll
  .Add Position:=InchesToPoints(1.25), _
           Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
  .Add Position:=InchesToPoints(3), _
           Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
End With

With a range, the actual selection (insertion point) never moves.  You can
click in the doc, run this macro, and then pick up where you clicked.

HTH
Ed

> > You would have to reveal how your macro is "pumping out the rest of the
> > document."
[quoted text clipped - 10 lines]
> But I'm not sure how to turn off the selection and return to my original
> position.  Any thoughts?  Thanks much.
Rick Charnes - 25 Oct 2005 22:09 GMT
Right, I had a feeling that using a range was the answer.  But when I
paste this in to my VBA editor, it doesn't like the below line which
gets split over two lines with "Start," ending line 1 -- both lines
appear in red.  Am I typing something wrong?  Thanks.

> Set rngWork = ActiveDocument.Range(Selection.Range.Start,
> ActiveDocument.Content.End)
Ed - 25 Oct 2005 22:40 GMT
Sorry - should have warned you about the line stuff.  Lines of code can
often get pretty long - too long for the NG reader to handle without
breaking.  And of course they will always break in bad spots!  That all
should be on one line.

Alternatively, you can use a "line break" (I don't know what the proper VBA
name is), which is a space and an underscore before you hit Enter.  So your
lines could be
   Set rngWork = ActiveDocument.Range(Selection.Range.Start, _
   ActiveDocument.Content.End)
or
   Set rngWork = ActiveDocument.Range _
   (Selection.Range.Start, ActiveDocument.Content.End)
whichever suits your purposes.

HTH
Ed

> Right, I had a feeling that using a range was the answer.  But when I
> paste this in to my VBA editor, it doesn't like the below line which
[quoted text clipped - 3 lines]
> > Set rngWork = ActiveDocument.Range(Selection.Range.Start,
> > ActiveDocument.Content.End)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.