Outlook tables

ldoodle

New Member
Joined
Mar 2, 2010
Messages
40
Office Version
  1. 365
Platform
  1. Windows
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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,223,790
Messages
6,174,600
Members
452,574
Latest member
hang_and_bang

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