Table Info in a Word Document

N

NJ

I have a Word 2003 document that has four tables in it. Using VBA; how do I
get information on the 3rd table (e.g. table3.column1.width)
 
D

Dave Lett

Hi,

You can use something like the following:

Dim oCol As Column
Set oCol = ActiveDocument.Tables(3).Columns(1)

MsgBox PointsToInches(oCol.Width)

HTH,
Dave
 
N

NJ

Dave,
I am trying to hide a column with the following code but it still displays a
column between column 4 and 6 and its width is 0.8666
How do I completely hide a column?

ActiveDocument.Tables(2).Columns(5).PreferredWidth = 0
ActiveDocument.Tables(2).LeftPadding = 0
ActiveDocument.Tables(2).RightPadding = 0
 
D

Dave Lett

Hi,

I don't know everything, but I feel okay about two answers that I have about
this issue (neither of which you'll like, I guess):

1) I don't think you can fully hide a table's column in Word. The width of
the column will always be there to some degree (at least in my testing,
which has NOT been exhaustive)
2) If you really want to hide a column, use Excel.

Sorry, I'm not trying to be glib, I just don't think you can do what you're
trying to do with Word.

Another method to do this would be to hide the contents of the column:
Dim oTbl As Table
Dim oCol As Column
Dim oRng As Range

Set oTbl = ActiveDocument.Tables(3)
Set oRng = oTbl.Range
Set oCol = oTbl.Columns(1)
oCol.Select
Selection.Font.Hidden = True

Convert the table to text:
oTbl.ConvertToText Separator:=wdSeparateByTabs

Replace a hidden tab, with some other character:
With oRng.Find
.ClearFormatting
.Text = "^t"
.Font.Hidden = True
With .Replacement
.ClearFormatting
.Text = ","
End With
.Execute Replace:=wdReplaceAll
End With

Covert the text back to a table:
oRng.ConvertToTable Separator:=wdSeparateByTabs

So, then, you end up with the column hidden, but now you have a table with
no borders and you're left with the problem of "adding" the column back.

HTH,
Dave
 
E

Ed

Dave and NJ - My Table dialog just told me the measurement has to be at
least 0.02 inches. If you do that and hide one of the side borders, it
looks like the column isn't there.

Ed
 

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