Formatting Table Columns

B

Bryan Dickerson

The following code snippet is from a VB6 routine that is trying to format
the columns in a table. It, however, gets an error upon attempting to set
the PreferredWidthType property. Any ideas?

Set oTable = oWDoc.Tables(1)
'
' code that works and is unimportant to this question goes here
'
oTable.Rows(1).Select
oWord.Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Set oRange = oWord.Selection.Range
With oRange
.Columns(1).PreferredWidthType = wdPreferredWidthPoints
.Columns(1).PreferredWidth = oWord.InchesToPoints(0.4)
End With

TIA!
 
H

Helmut Weber

Hi Bryan,

works perfectly here and now, so I'd say,
something else must be wrong.

Maybe somebody knows, whether,
.Columns(1).PreferredWidthType = wdPreferredWidthPoints
perhaps, isn't available in all version of Word.

Private Sub Command1_Click()
Dim oWrd As Word.Application
Dim oTbl As Word.Table
Dim oRng As Word.Range
Set oWrd = GetObject(, "Word.Application")
Set oTbl = oWrd.Documents(1).Tables(1)
oTbl.Rows(1).Select
oWrd.Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Set oRng = oWrd.Selection.Range
With oRng
.Columns(1).PreferredWidthType = wdPreferredWidthPoints
.Columns(1).PreferredWidth = oWrd.InchesToPoints(0.4)
End With
' ...
End Sub

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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