Newbie: How to select left cell in first row in a table?


F

Frank

I want to iterate through each table in a document and make som column
adjustments, see code below.

However, in order to make this work, I guess I need to select left cell in
first row in the table before performing a table column title search and the
column adjustment.

How do I select the left cell in first row in the table?

Regards

Frank Krogh



Sub AdjustTables()
Application.ScreenUpdating = False
For Each aTable In ActiveDocument.Tables
aTable.AutoFitBehavior (wdAutoFitContent)
FixTablesColumns
Next aTable
Application.ScreenUpdating = True
End Sub

Sub FixTablesColumns()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "given table column title"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = CentimetersToPoints(2.24)
Selection.Find.ClearFormatting
Selection.MoveLeft Unit:=wdCharacter, Count:=1

' other table column adjustments here ...

end sub
 
Ad

Advertisements

F

Frank

Thank you for the suggestion.

However, I get a run time error '438': Object doesn't support this property
or method, when I try this code:

Dim pCell As Word.Cell

Application.ScreenUpdating = False
For Each aTable In ActiveDocument.Tables
aTable.AutoFitBehavior (wdAutoFitContent)
Set pCell = aTable.Cells(1, 1)
FixTableColumns
Next aTable
Application.ScreenUpdating = True
 
Ad

Advertisements

T

Tony Jollans

Use Cell instead of Cell*s*.

--
Enjoy,
Tony

Frank said:
Thank you for the suggestion.

However, I get a run time error '438': Object doesn't support this property
or method, when I try this code:

Dim pCell As Word.Cell

Application.ScreenUpdating = False
For Each aTable In ActiveDocument.Tables
aTable.AutoFitBehavior (wdAutoFitContent)
Set pCell = aTable.Cells(1, 1)
FixTableColumns
Next aTable
Application.ScreenUpdating = True
 

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