Selection.Information Question

S

spunkymuffmonkey

Hi all,

I am wondering if it is possible to return the table number of the current
selection.

I have a document that contains a button for creating a new table (formatted
in a specific way), each new table contains a activeX control checkbox that
if the user clicks they are prompted with a msgbox that asks if they wish to
delete part of this new table.

Each new ActiveX control is named checkbox1, checkbox2 of course.
potentially users could create anywhere up to 200 new tables and without
creating a separate sub for each checkbox in anticipation (i.e. document
template would have possibly 199 redundant subs in it) I am at a loss how I
can best manage this.

One thought I had is if I could establish what tablenumber the checkbox was
fired from then I could find someway of creating a 'one sub works for all
checkboxes' type situation.

I hope that the above makes sense and that somebody has a suggestion for me!

Many thanks for looking
 
J

Jay Freedman

You don't need to know the table's number within the document to work with
it. Whenever the cursor is within any table, the expression
Selection.Tables(1) represents the single table that contains the Selection.
It is NOT the first table in the document, which would be represented by
ActiveDocument.Tables(1). This example shows how you can use the expression:

Sub x()
Dim myTable As Table
If Selection.Information(wdWithInTable) Then
Set myTable = Selection.Tables(1)

' do something with myTable, for example
myTable.Rows.Shading _
.BackgroundPatternColor = wdColorBlue
End If
End Sub

This works regardless of which table contains the cursor.

As an aside, I think you may have trouble with a document that contains a
large number of ActiveX controls. They tend to make Word respond slowly and
scroll erratically.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
S

spunkymuffmonkey

Thanks Jay!

Jay Freedman said:
You don't need to know the table's number within the document to work with
it. Whenever the cursor is within any table, the expression
Selection.Tables(1) represents the single table that contains the Selection.
It is NOT the first table in the document, which would be represented by
ActiveDocument.Tables(1). This example shows how you can use the expression:

Sub x()
Dim myTable As Table
If Selection.Information(wdWithInTable) Then
Set myTable = Selection.Tables(1)

' do something with myTable, for example
myTable.Rows.Shading _
.BackgroundPatternColor = wdColorBlue
End If
End Sub

This works regardless of which table contains the cursor.

As an aside, I think you may have trouble with a document that contains a
large number of ActiveX controls. They tend to make Word respond slowly and
scroll erratically.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.



.
 

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