ldoodle

New Member
Joined
Mar 2, 2010
Messages
37
Hey,

Given this code, in Outlook 2010 (is fine in 2016!?) why would it error out on the lines setting the PreferredWidth of each column:

Code:
...
...
Set Selection = Inspector.WordEditor.Application.Selection
With Selection
    If .Tables.Count < 1 Then
    
        Set Table = .Tables.Add(Range:=.Range, NumRows:=1, NumColumns:=4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed)
        .InsertRows NumRows:=FileCount
        
        With Table
        
            .Style = "Table Grid"
            .PreferredWidthType = wdPreferredWidthPoints
            .PreferredWidth = 700
            .TopPadding = CentimetersToPoints(0.12)
            .BottomPadding = CentimetersToPoints(0.12)
            .Columns.PreferredWidthType = wdPreferredWidthPoints
           ----> .Columns(1).PreferredWidth = 30 <----
           ----> .Columns(2).PreferredWidth = 470 <----
           ----> .Columns(3).PreferredWidth = 90 <----
           ----> .Columns(4).PreferredWidth = 110 <----
            
            With .Borders
            
                .Enable = True
                .OutsideColor = 5263440
                .InsideColor = 5263440
                
            End With
            
            With .Rows.First
            
                .HeadingFormat = True
                .Height = 20
                .Shading.BackgroundPatternColor = ColorPicker()
                .Cells.VerticalAlignment = wdCellAlignVerticalCenter
                .Cells(1).Range.Text = "No."
                .Cells(2).Range.Text = "Name"
                .Cells(3).Range.Text = "Size"
                .Cells(4).Range.Text = "Expiry Date"
                
                With .Range
                
                    .Font.Color = 16777215
                    .Font.Size = 12
                    
                End With
                
            End With
            
        End With
        
    Else
    
        Set Table = .Tables(1)
        .InsertRows NumRows:=FileCount
        
    End If
    
End With
...
...

The error is "5992: Cannot access individual columns in this collection because the table has mixed cell widths." I understand this to be because there are merged cells, but there aren't any in my table - it's a brand new table each time.

The exact same code seems to work OK directly in Word VBA editor.

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,214,839
Messages
6,121,887
Members
449,057
Latest member
Moo4247

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top