将一页上的 powerpoint table 中的整行粘贴到另一页上的另一页 table
Paste entire row from powerpoint table on one page into another table on prior page
与我在确定如何查看形状是否溢出页面边界的问题相关 ()
我需要将一页上的 table 行移动到上一页。
确定我需要剪切的行非常简单(为简洁起见,我将那部分代码省略了)。我遇到问题的地方是如何将其粘贴回上一页的 table 的方法(table 具有相同的列尺寸)。
在UI中,只需将光标置于目标行的第一个单元格并点击粘贴即可。这完全复制了剪切行的列结构。在 VB 中,我能做的最好的事情就是将剪切行(所有列)的整个文本粘贴到一个单元格中。我似乎无法获得可以复制 UI 中发生的事情的 VB 代码。我缺少什么命令?
For y = 2 To c
Set oSh = ActivePresentation.Slides(k + 1).Shapes("ProgTable")
With oSh.Table
.Rows(y).Select
End With
Windows(1).Selection.Cut
Set oSh = ActivePresentation.Slides(k).Shapes("ProgTable")
With oSh.Table
.Rows.Add (-1)
.Cell(oSh.Table.Rows.Count,1)textFrame.TextRange.Paste 'pastes all columns into the one cell
End With
Next y
备用代码行来粘贴我无法开始工作的剪贴板
.Rows(oSh.Table.Rows.Count).Cells.Item.Shape.TextFrame.TextRange.PasteSpecial (PpPasteDataType.ppPasteHTML)
'does not work, gives compile error on ITEM argument not optional
您正在粘贴到 TextRange
,而不是 table/row 本身。 PPT 的对象模型中肯定有一些时髦的东西,而一些看起来应该是直观的 (copy/paste) 的动作往往不是。在这些情况下,Application.CommandBars.ExecuteMSO
方法通常是我开始的地方(如果您 copying from/between different applications 喜欢 Excel>PowerPoint、Word>PowerPoint 等,这也非常有用)
我这样做是为了测试,它按预期工作,所以它应该让你走上正轨:
Sub CopyRowToAnotherTable()
Dim tbl1 As Table
Dim tbl2 As Table
Dim sld1 As Slide
Dim sld2 As Slide
Dim pres As Presentation
Dim shp As Shape
Set pres = ActivePresentation
Set sld1 = pres.Slides(1)
Set sld2 = pres.Slides(2)
Set tbl1 = sld1.Shapes(1).Table
Set tbl2 = sld2.Shapes(1).Table
'Cut the last row from tbl2:
sld2.Select '## Powerpoint requires the slide to be active/view in order to select shapes on the slide
With tbl2
.Rows(.Rows.Count).Select
pres.Windows(1).Selection.Cut
End With
'Insert in tbl1
With tbl1
.Rows.Add -1
sld1.Select
.Rows(.Rows.Count).Select
pres.Application.CommandBars.ExecuteMso "Paste"
End With
End Sub
所以在你的代码中,我认为这应该可行:
With oSh.Table
'## select the slide:
.Parent.Parent.Select
.Rows.Add (-1)
.Rows(.Rows.Count).Select
Application.CommandBars.ExecuteMso "Paste"
End With
关于 ExecuteMso
方法的棘手部分主要是它没有很好的记录,或者是,但是很难 找到 dox,所以这里是来自 a previous answer 的参考:
Documentation on the ExecuteMso method:
http://msdn.microsoft.com/en-us/library/office/ff862419.aspx
Downloadable document containing the idMSO parameters for each Office
Application:
http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=6627
与我在确定如何查看形状是否溢出页面边界的问题相关 (
我需要将一页上的 table 行移动到上一页。
确定我需要剪切的行非常简单(为简洁起见,我将那部分代码省略了)。我遇到问题的地方是如何将其粘贴回上一页的 table 的方法(table 具有相同的列尺寸)。
在UI中,只需将光标置于目标行的第一个单元格并点击粘贴即可。这完全复制了剪切行的列结构。在 VB 中,我能做的最好的事情就是将剪切行(所有列)的整个文本粘贴到一个单元格中。我似乎无法获得可以复制 UI 中发生的事情的 VB 代码。我缺少什么命令?
For y = 2 To c
Set oSh = ActivePresentation.Slides(k + 1).Shapes("ProgTable")
With oSh.Table
.Rows(y).Select
End With
Windows(1).Selection.Cut
Set oSh = ActivePresentation.Slides(k).Shapes("ProgTable")
With oSh.Table
.Rows.Add (-1)
.Cell(oSh.Table.Rows.Count,1)textFrame.TextRange.Paste 'pastes all columns into the one cell
End With
Next y
备用代码行来粘贴我无法开始工作的剪贴板
.Rows(oSh.Table.Rows.Count).Cells.Item.Shape.TextFrame.TextRange.PasteSpecial (PpPasteDataType.ppPasteHTML)
'does not work, gives compile error on ITEM argument not optional
您正在粘贴到 TextRange
,而不是 table/row 本身。 PPT 的对象模型中肯定有一些时髦的东西,而一些看起来应该是直观的 (copy/paste) 的动作往往不是。在这些情况下,Application.CommandBars.ExecuteMSO
方法通常是我开始的地方(如果您 copying from/between different applications 喜欢 Excel>PowerPoint、Word>PowerPoint 等,这也非常有用)
我这样做是为了测试,它按预期工作,所以它应该让你走上正轨:
Sub CopyRowToAnotherTable()
Dim tbl1 As Table
Dim tbl2 As Table
Dim sld1 As Slide
Dim sld2 As Slide
Dim pres As Presentation
Dim shp As Shape
Set pres = ActivePresentation
Set sld1 = pres.Slides(1)
Set sld2 = pres.Slides(2)
Set tbl1 = sld1.Shapes(1).Table
Set tbl2 = sld2.Shapes(1).Table
'Cut the last row from tbl2:
sld2.Select '## Powerpoint requires the slide to be active/view in order to select shapes on the slide
With tbl2
.Rows(.Rows.Count).Select
pres.Windows(1).Selection.Cut
End With
'Insert in tbl1
With tbl1
.Rows.Add -1
sld1.Select
.Rows(.Rows.Count).Select
pres.Application.CommandBars.ExecuteMso "Paste"
End With
End Sub
所以在你的代码中,我认为这应该可行:
With oSh.Table
'## select the slide:
.Parent.Parent.Select
.Rows.Add (-1)
.Rows(.Rows.Count).Select
Application.CommandBars.ExecuteMso "Paste"
End With
关于 ExecuteMso
方法的棘手部分主要是它没有很好的记录,或者是,但是很难 找到 dox,所以这里是来自 a previous answer 的参考:
Documentation on the ExecuteMso method:
http://msdn.microsoft.com/en-us/library/office/ff862419.aspx
Downloadable document containing the idMSO parameters for each Office Application:
http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=6627