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?
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
Maybe something like this:
Dim MyTableRef As Table
Set MyTableRef = pptApp.CommandBars.ExecuteMso("PasteAsTableSourceFormatting")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.