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 / December 2007

Tip: Looking for answers? Try searching our database.

Remove specific tabstop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Foley - 20 Dec 2007 13:10 GMT
I have code that goes through my document and removes all instances of a
BarTab (at 7.25 inches) and changes the RED color back to BLACK.  I am
trying to modify my existing macro to just remove the current TAB on the
paragraph where my cursor lives.

My current macro is:

Sub RemoveRedLine()

' This removes the RedLines (normally when a PCN'd document is now Rev'd)

Dim Msg, Style, Title, Response
Msg = "You are about to remove all redlines!  Do you want to continue?"    '
Define message
Style = vbYesNo + vbDefaultButton2    ' Define buttons.
Title = "Redline Deletion"    ' Define title.

Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then    ' User chose Yes.

Application.ScreenUpdating = False

Dim oPara As Paragraph
Dim oTabStop As TabStop
 For Each oPara In ActiveDocument.Paragraphs
   For Each oTabStop In oPara.TabStops
     If oTabStop.Position = InchesToPoints(7.25) _
     And oTabStop.Alignment = wdAlignTabBar Then
       oTabStop.Clear
     End If
   Next oTabStop
 Next oPara

   Selection.WholeStory
   Selection.Font.Color = wdColorBlack
   Selection.HomeKey Unit:=wdStory

Application.ScreenUpdating = True
Else    ' User chose No.
End If

End Sub

I've tried using:

Dim oTabStop As TabStop
   For Each oTabStop In Selection.Paragraphs
     If oTabStop.Position = InchesToPoints(7.25) _
     And oTabStop.Alignment = wdAlignTabBar Then
       oTabStop.Clear
     End If
   Next oTabStop

It is easy to clear ALL the TABs of the current paragraph, but I just want
to clear the one at 7.25.

Any assistance would be greatly appreciated.

Bill
Klaus Linke - 21 Dec 2007 03:26 GMT
Hi Bill,

The code to remove the tab stop works fine for me.
What is it that does not work as you expect?

BTW, it might be safer not to rely on infinite precision and use something like
If Abs(oTabStop.Position - InchesToPoints(7.25)) < 1 Then
rather than
If oTabStop.Position = InchesToPoints(7.25)  Then

But I doubt that's an issue in your case.

Regards,
Klaus
Bill Foley - 22 Dec 2007 03:53 GMT
Klaus,

Thanks for the assistance.  Sorry been out of the office (moving).  I can't
remember if you helped me out with this code originally or not, but I want
to be able to remove the redline for the paragraph where the cursor is
placed.  The original macro works to remove ALL redlines and BarTabs, but
the code below does not remove it for the line I am on.  Not sure why...

This code here does not work.  It debugs to the second line:

Dim oTabStop As TabStop
   For Each oTabStop In Selection.Paragraphs
     If oTabStop.Position = InchesToPoints(7.25) _
     And oTabStop.Alignment = wdAlignTabBar Then
       oTabStop.Clear
     End If
   Next oTabStop

Bill

Hi Bill,

The code to remove the tab stop works fine for me.
What is it that does not work as you expect?

BTW, it might be safer not to rely on infinite precision and use something
like
If Abs(oTabStop.Position - InchesToPoints(7.25)) < 1 Then
rather than
If oTabStop.Position = InchesToPoints(7.25)  Then

But I doubt that's an issue in your case.

Regards,
Klaus
Klaus Linke - 22 Dec 2007 18:30 GMT
> I can't remember if you helped me out with this code originally or not

Hi Bill,

I think it was about something else?

> the code below does not remove it for the line I am on.  

As I said, it works fine for me, removing the bar tab from the paragraph(s) in the selection (not lines, but I'm sure you are aware of that).

It does not seem to work with non-contiguous selections (... the kind you can make by selecting something, then holding down Ctrl and selecting something elsewhere) -- in that case, it only works on the last "selection".

I guessed it might fail is if the paragraphs are in a style that's set to automatically update, but I just checked and it works even then.

No idea what else might go wrong... Is there anything special (tables, text boxes, frames...)?
Is "Track changes" turned on?

You can mail me the doc, but I will be away for a few weeks soon and am not sure I'll manage to look at it before.

Regards,
Klaus
Bill Foley - 23 Dec 2007 03:31 GMT
It does not work for me.  Go figure.  Maybe just to simplify things, what
would the code be to remove a BarTab set at 7.25 on a paragraph where your
cursor is?  There might be other TABS on that same paragraph so I can't use
"ClearAll".

Bill
> I can't remember if you helped me out with this code originally or not

Hi Bill,

I think it was about something else?

> the code below does not remove it for the line I am on.

As I said, it works fine for me, removing the bar tab from the paragraph(s)
in the selection (not lines, but I'm sure you are aware of that).

It does not seem to work with non-contiguous selections (... the kind you
can make by selecting something, then holding down Ctrl and selecting
something elsewhere) -- in that case, it only works on the last "selection".

I guessed it might fail is if the paragraphs are in a style that's set to
automatically update, but I just checked and it works even then.

No idea what else might go wrong... Is there anything special (tables, text
boxes, frames...)?
Is "Track changes" turned on?

You can mail me the doc, but I will be away for a few weeks soon and am not
sure I'll manage to look at it before.

Regards,
Klaus
Klaus Linke - 23 Dec 2007 08:12 GMT
> It does not work for me.  Go figure.  Maybe just to simplify things, what
> would the code be to remove a BarTab set at 7.25 on a paragraph where your
> cursor is?  There might be other TABS on that same paragraph so I can't use
> "ClearAll".

Now I'm confused  8-)
I thought that was what you are trying to do all along?

And you posted the code already:
   Dim oTabStop As TabStop
   For Each oTabStop In Selection.Paragraphs
     If oTabStop.Position = InchesToPoints(7.25) _
     And oTabStop.Alignment = wdAlignTabBar Then
       oTabStop.Clear
     End If
   Next oTabStop

Regards,
Klaus
Bill Foley - 23 Dec 2007 14:56 GMT
Klaus,

Okay, I give up.  When I use that EXACT code it fails on line 2 (For
Each...)

I will send you my file directly.

Bill
"Bill Foley" <billfoleyatcharterdotnet> wrote:
> It does not work for me.  Go figure.  Maybe just to simplify things, what
> would the code be to remove a BarTab set at 7.25 on a paragraph where your
> cursor is?  There might be other TABS on that same paragraph so I can't
> use
> "ClearAll".

Now I'm confused  8-)
I thought that was what you are trying to do all along?

And you posted the code already:
   Dim oTabStop As TabStop
   For Each oTabStop In Selection.Paragraphs
     If oTabStop.Position = InchesToPoints(7.25) _
     And oTabStop.Alignment = wdAlignTabBar Then
       oTabStop.Clear
     End If
   Next oTabStop

Regards,
Klaus
Klaus Linke - 24 Dec 2007 11:51 GMT
Oops... thought I had copied your code to test it, but just noticed I hadn't.
It should be
 For Each oTabStop In Selection.Paragraphs(1).TabStops
if you just want it to work on the current paragraph.

Selection(1) always refers to the first paragraph in the selection, even if only part of it is selected, or even if the selection is collapsed (just an insertion point).

You need a collection of TabStops, so Selection.Paragraphs won't work.

Selection.Paragraphs.TabStops won't work either: Though it does return a TabStops collection, the values of just about all the properties of those TabStops return wdUndefined (9999999), unless all the tab stops in the selection are identical.

One might argue that this is a bit of a bug. OTOH, a tab stop belongs to an individual paragraph, so it's probably not easy to define what Selection.Paragraphs.TabStops should return.

Happy Christmas,
Klaus

> Klaus,
>
[quoted text clipped - 25 lines]
> Regards,
> Klaus
Bill Foley - 25 Dec 2007 00:58 GMT
Ah, Bach!  Thanks!

Merry Christmas!

Bill
Oops... thought I had copied your code to test it, but just noticed I
hadn't.
It should be
 For Each oTabStop In Selection.Paragraphs(1).TabStops
if you just want it to work on the current paragraph.

Selection(1) always refers to the first paragraph in the selection, even if
only part of it is selected, or even if the selection is collapsed (just an
insertion point).

You need a collection of TabStops, so Selection.Paragraphs won't work.

Selection.Paragraphs.TabStops won't work either: Though it does return a
TabStops collection, the values of just about all the properties of those
TabStops return wdUndefined (9999999), unless all the tab stops in the
selection are identical.

One might argue that this is a bit of a bug. OTOH, a tab stop belongs to an
individual paragraph, so it's probably not easy to define what
Selection.Paragraphs.TabStops should return.

Happy Christmas,
Klaus

"Bill Foley" <billfoleyatcharterdotnet> wrote:
> Klaus,
>
[quoted text clipped - 25 lines]
> Regards,
> Klaus
 
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.