首页 > 解决方案 > Powerpoint Macros: Column(unknown member) error at Columns.Width Formatting code

问题描述

I'm new to coding directly in the Powerpoint Macros interface, while learning formatting I hit a roadblock.

Slide 10 of Presentation has a 5 by 7 table. I would like to adjust the width of column 3.

The code I use is:

Sub FormatTables()

Dim s As Slide
Dim oSh As Shape
Dim oTbl As Table
Dim lRow As Long
Dim lCol As Long
Dim ThisRow As Integer

Set s = ActivePresentation.Slides(10)
s.Select

For Each oSh In s.Shapes
            If oSh.HasTable Then
                Set oTbl = oSh.Table
                oTbl.Columns(1).Width = 72 * 0.5
                oTbl.Columns(2).Width = 72 * 0.5
                oTbl.Columns(3).Width = 72 * 0.5
                
                For lRow = 1 To oTbl.Rows.Count
                    For lCol = 1 To oTbl.Columns.Count
                        With oTbl.Cell(lRow, lCol).Shape.TextFrame.TextRange
                            .Font.Name = "Georgia"
                            .Font.Size = 8
                        End With
                    Next
                Next
            End If
Next

The error I get is: "Columns (unknown member): Integer out of range. 3 is not the valid range of 1 to 2.

Also, the width of columns 1 and 2 are adjusting successfully, but the macro hits the error at the line of code of Column 3.

Is there anything I missed?

标签: vbapowerpoint

解决方案


推荐阅读