阻止 vba 生成的 PowerPoint table 自动调整行大小
Prevent vba generated PowerPoint table from auto-sizing rows
我有一个大型宏,它根据 excel 值在 powerpoint 中生成并填充 table。我根据特定参数手动调整行的大小,但我 运行 遇到了一个非常烦人的问题,如果文本从该特定单元格溢出,我似乎无法阻止行自动调整大小。我试过使用 textframe
和 textframe2
"autosize" 属性 但这会在第一次调用时出错,指出指定的值超出范围。错误编号是 -2147024809 (80070057),但我怀疑它是否有用。除了编写代码以在文本溢出时手动缩短文本之外,还有什么方法可以防止这种自动调整大小?
当文本太多无法放入单元格时,您希望发生什么情况? PowerPoint 中没有 UI 概念来防止基于单元格溢出的行自动调整大小,因为附加文本无处可去,如在 PowerPoint 中的单元格中键入所示。因此没有 API 做同样的事情。我会记录插入文本前后的行,并按照您所说的逐字截断,直到行高 returns 到原始值。
RGA,
你的问题的答案是肯定的;你可以这样做。此主题在以下线程中讨论:
不过不知道这个技巧对ppt 2016是否还'works'。我实现了这样的代码,然后我'upgraded'到office 2016;现在它不起作用。
话虽这么说,这个 是 我的代码(调整文本大小直到它 'fit'):
...
Do Until (table.rows(1).height + table.rows(2).height < TABLE_HEIGHT) or (table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size = 1)
If table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size = 1 Then
table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size = 27
table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size = table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size - 1
table.Cell(2, 3).Shape.TextFrame.TextRange.Font.size = table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size
Else
table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size = table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size - 1
End If
Loop
为了恢复 ppt 2016 中的一些功能,我决定重写我的代码以限制显示的行数以防止 'resize' table 调用:
...
table.Cell(1, 1).Shape.TextFrame.TextRange = table.Cell(1, 1).Shape.TextFrame.TextRange.lines(1,2)
table.Cell(2, 2).Shape.TextFrame.TextRange = table.Cell(2,2).Shape.TextFrame.TextRange.lines(1,1)
table.Cell(2, 3).Shape.TextFrame.TextRange = table.Cell(2, 3).Shape.TextFrame.TextRange.lines(1,1)
理论上可以用.height; .文本范围;和字体的高度来确定您需要的字体大小,以便 'shrink' 文本适合。
我有一个大型宏,它根据 excel 值在 powerpoint 中生成并填充 table。我根据特定参数手动调整行的大小,但我 运行 遇到了一个非常烦人的问题,如果文本从该特定单元格溢出,我似乎无法阻止行自动调整大小。我试过使用 textframe
和 textframe2
"autosize" 属性 但这会在第一次调用时出错,指出指定的值超出范围。错误编号是 -2147024809 (80070057),但我怀疑它是否有用。除了编写代码以在文本溢出时手动缩短文本之外,还有什么方法可以防止这种自动调整大小?
当文本太多无法放入单元格时,您希望发生什么情况? PowerPoint 中没有 UI 概念来防止基于单元格溢出的行自动调整大小,因为附加文本无处可去,如在 PowerPoint 中的单元格中键入所示。因此没有 API 做同样的事情。我会记录插入文本前后的行,并按照您所说的逐字截断,直到行高 returns 到原始值。
RGA,
你的问题的答案是肯定的;你可以这样做。此主题在以下线程中讨论:
不过不知道这个技巧对ppt 2016是否还'works'。我实现了这样的代码,然后我'upgraded'到office 2016;现在它不起作用。
话虽这么说,这个 是 我的代码(调整文本大小直到它 'fit'):
...
Do Until (table.rows(1).height + table.rows(2).height < TABLE_HEIGHT) or (table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size = 1)
If table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size = 1 Then
table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size = 27
table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size = table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size - 1
table.Cell(2, 3).Shape.TextFrame.TextRange.Font.size = table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size
Else
table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size = table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size - 1
End If
Loop
为了恢复 ppt 2016 中的一些功能,我决定重写我的代码以限制显示的行数以防止 'resize' table 调用:
...
table.Cell(1, 1).Shape.TextFrame.TextRange = table.Cell(1, 1).Shape.TextFrame.TextRange.lines(1,2)
table.Cell(2, 2).Shape.TextFrame.TextRange = table.Cell(2,2).Shape.TextFrame.TextRange.lines(1,1)
table.Cell(2, 3).Shape.TextFrame.TextRange = table.Cell(2, 3).Shape.TextFrame.TextRange.lines(1,1)
理论上可以用.height; .文本范围;和字体的高度来确定您需要的字体大小,以便 'shrink' 文本适合。