Vba Powerpoint 为表格命名 [英] Vba Powerpoint name a table

查看:68
本文介绍了Vba Powerpoint 为表格命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用以下代码将表格从 Excel 粘贴到 PowerPoint:

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

pptApp.CommandBars.ExecuteMso ("PasteAsTableSourceFormatting")

这张幻灯片上还有其他形状.如何让 PowerPoint 找到幻灯片上粘贴的表格并命名?

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

推荐答案

每当您在 PowerPoint 中粘贴某些内容时,它都会出现在最顶层,以便您可以获取对它的引用并可以选择使用此功能设置名称:

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

这篇关于Vba Powerpoint 为表格命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆