What are Mixed Tab Settings ? Word 2000 SP3

V

vbasteve

I understand that the "TabStops collection represents all the custom and
default tab stops in a paragraph or group of paragraphs."
I'm creating tabstops via code such like this:

Dim HPosRel2Page As Integer
Application.Selection.Collapse direction:=wdCollapseEnd
HPosRel2Page =
Application.Selection.Information(wdHorizontalPositionRelativeToPage)
'Creates a tab stop at current IP location...
Application.ActiveDocument.Paragraphs.TabStops.Add HPosRel2Page

I have also set the default tab stop for the activeDoc to 500pt.
(essentially removing all default tab stops)
Application.ActiveDocument.DefaultTabStop = 500

If I run the following code snippit all is good,
iNumTabs = Application.ActiveDocument.Paragraphs.tabStops.Count

However, if I try to manually adjust a tabstop that was added via code by
using the ruler (Left click and drag) and then run
iNumTabs = .Paragraphs.tabStops.Count

I am getting the following error message:
Runtime Error 5920
This TabStops Collection Has Mixed Tab Settings

I can supress the error message with a simple function call, but I loose the
ability to manually adjust a tabstop.

Public Function IsCustomTabStop(iTabNum As Integer) As Boolean
'Check to see if this tab is a custom tab stop....
'Comment out On Error to display error message...
On Error Resume Next
If Application.ActiveDocument.Paragraphs.tabStops(iTabNum).CustomTab
Then
IsCustomTabStop = True
Else
IsCustomTabStop = False
End If
End Function

So my question is: What are Mixed Tab Settings?
 
S

Stefan Blom

In code, you are setting the tab stops for all paragraphs in the
active document. Then, when you are using drag and drop, the
modification is being done for a single paragraph (unless you select
the whole document before you do it), which modifies part of the
ActiveDocument.Paragraphs.TabStops collection. That is why you are
getting the error message.

--
Stefan Blom
Microsoft Word MVP


in message
news:%[email protected]...
 
S

Stefan Blom

In other words, adding a tab stop or modifying an existing one within
a single paragraph, modifies the TabStops collection for that
particular paragraph. As a consequence, there is no longer a TabStops
collection which accurately reflects the tab settings for the
referenced Paragraphs collection.

What you can do is access the TabStops collections of each individual
Paragraph:

Sub CountTabStopsInDoc()
Dim counter As Long
Dim p As Paragraph
For Each p In ActiveDocument.Paragraphs
counter = counter + p.TabStops.Count
Next p
Debug.Print "Number of tab stops in document: " & _
counter
End Sub

Note, however, that it would make more sense to set tab stops for
paragraph styles (in the user interface or via VBA).

--
Stefan Blom
Microsoft Word MVP


in message
 
V

vbasteve

Stefan,

Thank you, I understand how tabs are being set now and will adjust my code
accordingly.
In regards to setting the tab stops for paragraph style(s) I agree. However,
in this case I don't have that luxury.

There is no question that follows, but I'm just describing a problem that
was solved with MS Word VBA.

Let me start by giving a 30,000 foot overview of what I'm working with.

What I have are several thousands .rtf reports straight from the main frame.
Each report contains anywhere from 40 to 200 pages. Within each report I
need to identify (2) "table-like" structures. I say "table-like" because
visually the data lines up in column, row format, but in reality there is
nothing to identify these "table-like" structures as "tables". In most cases
each line ends with a carriage return. [vba.chr$(13)] So potentially there
could be up to 10,000 individual paragraphs per file.
Now the fun starts. For every file, each "table-like" structure has its own
format or in this case no format other than visually the data appears to be
in columns.

A very simplistic example might go something like this:
File_1_Table_1 might look like this: (Set 4 Columns)
" kkkkk rrrrr
qqqqqqqqqqqqqqq"
Debug.Print vba.space(1);
Debug.Print vba.String$(5,"k");vba.space(10);vba.String$(5,"r");
Debug.Print vba.space(35);
Debug.Print vba.String$(15,"q");vba.space(2); vba.chr$(13)

But File_2_Table_1 might look like this: (Set 4 Columns)
" kkkkkkkkkkkkkkkkkkkkkkkkk rrrrrrr qqqqqqqqqqqqq
xxxxx "
Debug.Print VBA.Space(1);
Debug.Print VBA.String$(25,"k");VBA.Space(4);VBA.String$(7, "r");
Debug.Print VBA.Space(12);VBA.String$(13,"q");
Debug.Print VBA.Space(6); VBA.String$(5, "x"); VBA.Chr$(13)

And File_3_Table_1 could have "weird" characters that would throw off
identifing the first position of a series of spaces such as: (Set 3 Columns)
iPos = VBA.InStr(iStart, myString, VBA.Space$(2), vbBinaryCompare)
Debug.Print "Mr.Jones - is sleeping in a tree"
Debug.Print "Mr.Jones"; VBA.Space$(1);
Debug.Print VBA.Chr$(45); VBA.Space$(1);
Debug.Print "is sleeping"; VBA.Space$(50);"in a tree"; VBA.Chr$(13)


So, what I have is no formal file structure other than visually, the data
displays in column, row format.
There is no guarentee that the data contained within each "table-like"
structure will even have the same number of columns.
There are embedded symbols that make separating out the column widths based
on multiple space occurrnances less than an ideal solution.

Thus, it seemed like a good idea at the time to scroll into view a
"table-like" structure, point and click and set a tab stop precisely in the
document window via code. And if I later discovered a particular column
needed a manual adjustment I would use a drag and drop approach. But now, I
will make sure that
any manual adjustments are applied in a more consistant fashion.
Thank you again for your help.
 
S

Stefan Blom

You may want to post this as a question in a separate thread; it is
likely that someone who knows more about VBA than I do can suggest a
way to properly format the reports.

--
Stefan Blom
Microsoft Word MVP


in message
Stefan,

Thank you, I understand how tabs are being set now and will adjust my code
accordingly.
In regards to setting the tab stops for paragraph style(s) I agree. However,
in this case I don't have that luxury.

There is no question that follows, but I'm just describing a problem that
was solved with MS Word VBA.

Let me start by giving a 30,000 foot overview of what I'm working with.

What I have are several thousands .rtf reports straight from the main frame.
Each report contains anywhere from 40 to 200 pages. Within each report I
need to identify (2) "table-like" structures. I say "table-like" because
visually the data lines up in column, row format, but in reality there is
nothing to identify these "table-like" structures as "tables". In most cases
each line ends with a carriage return. [vba.chr$(13)] So potentially there
could be up to 10,000 individual paragraphs per file.
Now the fun starts. For every file, each "table-like" structure has its own
format or in this case no format other than visually the data appears to be
in columns.

A very simplistic example might go something like this:
File_1_Table_1 might look like this: (Set 4 Columns)
" kkkkk rrrrr
qqqqqqqqqqqqqqq"
Debug.Print vba.space(1);
Debug.Print vba.String$(5,"k");vba.space(10);vba.String$(5,"r");
Debug.Print vba.space(35);
Debug.Print vba.String$(15,"q");vba.space(2); vba.chr$(13)

But File_2_Table_1 might look like this: (Set 4 Columns)
" kkkkkkkkkkkkkkkkkkkkkkkkk rrrrrrr qqqqqqqqqqqqq
xxxxx "
Debug.Print VBA.Space(1);
Debug.Print VBA.String$(25,"k");VBA.Space(4);VBA.String$(7, "r");
Debug.Print VBA.Space(12);VBA.String$(13,"q");
Debug.Print VBA.Space(6); VBA.String$(5, "x"); VBA.Chr$(13)

And File_3_Table_1 could have "weird" characters that would throw off
identifing the first position of a series of spaces such as: (Set 3 Columns)
iPos = VBA.InStr(iStart, myString, VBA.Space$(2), vbBinaryCompare)
Debug.Print "Mr.Jones - is sleeping in a tree"
Debug.Print "Mr.Jones"; VBA.Space$(1);
Debug.Print VBA.Chr$(45); VBA.Space$(1);
Debug.Print "is sleeping"; VBA.Space$(50);"in a tree"; VBA.Chr$(13)


So, what I have is no formal file structure other than visually, the data
displays in column, row format.
There is no guarentee that the data contained within each "table-like"
structure will even have the same number of columns.
There are embedded symbols that make separating out the column widths based
on multiple space occurrnances less than an ideal solution.

Thus, it seemed like a good idea at the time to scroll into view a
"table-like" structure, point and click and set a tab stop precisely in the
document window via code. And if I later discovered a particular column
needed a manual adjustment I would use a drag and drop approach. But now, I
will make sure that
any manual adjustments are applied in a more consistant fashion.
Thank you again for your help.

Stefan Blom said:
In other words, adding a tab stop or modifying an existing one within
a single paragraph, modifies the TabStops collection for that
particular paragraph. As a consequence, there is no longer a TabStops
collection which accurately reflects the tab settings for the
referenced Paragraphs collection.

What you can do is access the TabStops collections of each individual
Paragraph:

Sub CountTabStopsInDoc()
Dim counter As Long
Dim p As Paragraph
For Each p In ActiveDocument.Paragraphs
counter = counter + p.TabStops.Count
Next p
Debug.Print "Number of tab stops in document: " & _
counter
End Sub

Note, however, that it would make more sense to set tab stops for
paragraph styles (in the user interface or via VBA).

--
Stefan Blom
Microsoft Word MVP


in message

Application.Selection.Information(wdHorizontalPositionRelativeToPage)
 

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