【问题标题】:VBA: Insert content from clipboard in a certain file format at a certain position in PowerpointVBA:在Powerpoint中的某个位置以某种文件格式从剪贴板插入内容
【发布时间】:2014-07-01 08:30:42
【问题描述】:

我正在寻找一个 vba 脚本,它将我的剪贴板的当前内容粘贴到一个可指定的位置(比如说在当前选定的幻灯片之外的右上角)。 我希望脚本将其粘贴为 .emf。但是,如果有人可以向我解释如何操作脚本来选择位置和另一个粘贴结尾,那就太好了。

提前感谢您的帮助。

编辑:我最终想要实现的是获取插入的剪贴板内容并使其左下对齐到已在 Powerpoint 中选择的形状,然后删除已经存在的形状。这样对于用户来说,程序将是: 1.复制例如从 excel 到剪贴板的图表 2.在PowerPoint幻灯片上选择一个形状 3. 运行脚本 4. 粘贴​​内容,左下对齐,然后删除旧形状

如果有人知道如何做到这一点,那就太好了。

【问题讨论】:

    标签: vba powerpoint


    【解决方案1】:

    您之前问题的答案的修改版本。您无法控制粘贴内容的位置,但您可以在粘贴时获取对该形状的引用,并使用该引用将其移动到您想要的位置:

    Dim oBackShape As Shape
    Dim oFrontShape As Shape
    Dim oSlide As Slide
    
    ' Now we'll assume that only one shape is selected:
    Set oBackShape = ActiveWindow.Selection.ShapeRange(1)
    ' Get a reference to the slide that the shape is on
    Set oSlide = oBackShape.Parent
    ' Paste the contents of the clipboard as EMF and
    ' get a reference to the new shape
    Set oFrontShape = oSlide.Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)
    
    With oFrontShape
        ' Left align them
        .Left = oBackShape.Left
        ' Bottom align them
        .Top = oBackShape.Top - (.Height - oBackShape.Height)
    End With
    
    oBackShape.Delete
    

    【讨论】:

    • 嗨,史蒂夫,非常感谢。这让我的日常工作变得不那么令人生畏,并把重要的任务放在前面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 2013-06-17
    • 1970-01-01
    • 2022-12-26
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    相关资源
    最近更新 更多