Really trick tab operation (that's extremely useful!)

J

Jared Goralnick

I've written a pretty neat set of macros that automatically create
underlines and form fields that a user of the form can then type over
without affecting the underlines...as it's such a pain to teach the
form developers how to work with them and it's also a rather tedious
process. But I have hit a roadblock...

I need to be able to programmatically change all the default tabstops
that are being used in a given line to custom tabstops. So for
instance, if the form developer pressed the tab key without setting a
custom tabstop for it and then ran one of my macros, things would get
all messed up as the tab they previously used would move to one of the
custom tabstops set by my macro. I think I have the process down, but
my VBA knowledge of how to do it is somewhat limited. So please let
me know if you can fill in any of the blanks... Here's what I have:

Sub ChangeDefaultTabstopsToCustoms()

' Need to find a way to get the current line in my range and then
' be able to place my selection at my previous cursor position
Dim rCurrentLine As Range
rCurrentLine = Selection. '??

' Need to put all the below stuff in a while loop, as it'll repeat
' while the find operation below still finds a new tab

' With the current line I need to start at its beginning char and
' search forward to see if there are any tab characters.
With rCurrentLine.Find
.ClearFormatting
.text = "^t"
.Forward = True
.ClearFormatting
End With
rCurrentLine.Find.Execute

' Now that I've found a tab, I need to find out it's location and
' if it applies to a custom tab or not. I think this is a two step
' process of finding it's location with the
' currentTab.Information(wdHorizontalPositionRelativeToTextBoundary
' property (divided by 72). Then cycling through my tabstops to find
' a tabstop at that location and see if it's a default or custom one,
' which is merely a matter of
' If TabStops(x).CustomTab
' and then setting it if not:
' .TabStops.Add Position:=InchesToPoints(dCurrentPosInInches), _
' Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
'
End Sub

Pain the butt, eh? I don't think this is rocket science, I'm just
missing some pieces. This'd be a useful macro for the net's
repertoire. Any help would be much appreciated!

Thanks!
Jared
 
J

JGM

Hi Jared,

Something crucial you seem to have missed, or, possibly, I do not quite
understand what you need to know...

Tab stops are paragraph settings, not line settings. This means you cannot
set different tab stops for different lines belonging to the same paragraph.
I other words, if your paragraph is made up of six lines, even if you cycle
through the 6 lines (which is possible...) the tab stops are the same for
all 6 lines; and, if you change one tab stop, your changes will affect all 6
lines.
In fact, lines do not exist in Word, I mean as a proper entity or object.

So, in your code, think of it as cycling through the paragraphs, not the
lines. Look up the paragraph object in the VBA help for more details on
that.

HTH
Cheers!
 
J

Jared Goralnick

Yes, I understand that all tabs are tied to paragraphs, and I
appreciate your clarification because I guess I was confusing by
referring to them as lines...but I still have the same problems.
Could anyone help to address my original question?

Thanks!

~Jared
 

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