Vba Powerpoint name a table

狂风中的少年 提交于 2019-12-08 03:41:57

问题


I just pasted a table from Excel to PowerPoint with this code:

pptApp.CommandBars.ExecuteMso ("PasteAsTableSourceFormatting")

There are other Shapes on this Slide. How can I make PowerPoint to find the pasted table on the Slide and name it?


回答1:


Whenever you paste something in PowerPoint it appears on the topmost layer so you can get a reference to it and optionally set the name with this function:

Option Explicit

' ***********************************************************
' Purpose:  Get the topmost shape from the current slide.
' Inputs:   sName - optionally rename the shape
' Outputs:  Returns a shape object if the slide is not empty.
' Author:   Jamie Garroch
' Company:  YOUpresent Ltd. http://youpresent.co.uk/
' ***********************************************************
Function GetPastedShape(Optional sName As String) As Shape
  Dim lCurSlide As Long ' current slide index
  lCurSlide = ActiveWindow.View.Slide.SlideIndex
  With ActivePresentation.Slides(lCurSlide)
    If .Shapes.Count = 0 Then Exit Function
    ' Set a reference to the shape on the top layer
    Set GetPastedShape = .Shapes(.Shapes.Count)
    If sName <> "" Then .Shapes(.Shapes.Count).Name = sName
    ' Pasted objects should already be selected so next line is optional
    GetPastedShape.Select
  End With
End Function



回答2:


Maybe something like this:

 Dim MyTableRef As Table
 Set MyTableRef = pptApp.CommandBars.ExecuteMso("PasteAsTableSourceFormatting")


来源:https://stackoverflow.com/questions/35059114/vba-powerpoint-name-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!