Remove specific tabstop

B

Bill Foley

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
 
K

Klaus Linke

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
 
B

Bill Foley

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
 
K

Klaus Linke

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
 
B

Bill Foley

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
Klaus Linke said:
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
 
K

Klaus Linke

Bill Foley said:
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 :cool:
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
 
B

Bill Foley

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 said:
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 :cool:
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
 
K

Klaus Linke

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
 
B

Bill Foley

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top