如何将表中选定的列调整为特定大小

  • 本文关键字:调整 vba powerpoint
  • 更新时间 :
  • 英文 :


我写了下面的内容来为选定的幻灯片创建表格。我想将偶数列的列宽设置为奇数列的2/3,但当我尝试设置宽度时,我找不到正确的方法。我尝试使用Set Columns.Width来命名表,但没有成功。

Sub NavigatorX()
Dim oSlide As Slide
Dim oShapeNavigator As Shape
Dim nCounter As Long
Dim iRow As Integer
Dim iColumn As Integer
Dim EvenCell_W As Single

For Each oSlide In ActivePresentation.Slides
If oSlide.CustomLayout.Name = "Section Header" Then
nCounter = nCounter + 1
ElseIf nCounter > 0 Then
Set oShapeNavigator = oSlide.Shapes.AddTable(1, 10, Left:=10, Top:=10, Width:=200, Height:=2)
oShapeNavigator.Fill.ForeColor.RGB = RGB(255, 128, 128)
oShapeNavigator.Name = "Navigator " & nCounter

With oShapeNavigator.Table
For iColumn = 2 To .Columns.Count Step 2

EvenCell_W = (oShapeNavigator.Width / .Columns.Count) * 2 / 3

With .Table.Columns(iColumn)                    
Set .Width = EvenCell_W  ' <-- here is where I cannot find a way to properly fit the column size
End With
End If
Next
End Sub

简化为演示列大小:

Sub NavigatorX()

Dim oSlide As Slide
Dim oShapeNavigator As Shape
Dim w, wNew, numCols As Long
Dim iColumn As Integer, nCounter As Long

Set oSlide = ActivePresentation.Slides(1)
Set oShapeNavigator = oSlide.Shapes.AddTable(1, 10, Left:=10, Top:=10, _
Width:=200, Height:=2)
nCounter = 1 'eg
With oShapeNavigator
.Fill.ForeColor.RGB = RGB(255, 128, 128)
.Name = "Navigator " & nCounter
w = .Width
With .Table
numCols = .Columns.Count
For iColumn = 1 To numCols
wNew = w / (numCols / 2) * IIf(iColumn Mod 2 = 0, 2 / 5, 3 / 5)
.Columns(iColumn).Width = wNew
Next
End With
End With

End Sub

最新更新