vba 将所有“工作表对象”转换为 powerpoint 中的图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13057432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:13:19  来源:igfitidea点击:

Convert all "Worksheet Objects" to images in powerpoint

vbapowerpointworksheet

提问by Ronnie

Really not sure what stack site to place this on. Feel free to move it to the correct one. My question isn't really related to programming, but I have a ton of power points with these "Worksheet Objects" embedded in the slides. Some appear to be graphs from excel as well as other chart type items from Visio. I need to convert all these "Worksheet Objects" to just images within the slide.

真的不确定将它放在哪个堆栈站点上。随意将其移至正确的位置。我的问题与编程并没有真正的关系,但我有大量的幻灯片,这些“工作表对象”嵌入在幻灯片中。有些似乎是来自 excel 的图表以及来自 Visio 的其他图表类型项目。我需要将所有这些“工作表对象”转换为幻灯片中的图像。

My process right now is copy the object > Paste as Image > Move to the correct location > Delete the "Worksheet Object". It's a very time consuming and tedious process. Is there a macro I can write or something that can convert all these objects automatically? I tried googling and no luck so far

我现在的过程是复制对象>粘贴为图像>移动到正确的位置>删除“工作表对象”。这是一个非常耗时且乏味的过程。是否有我可以编写的宏或可以自动转换所有这些对象的东西?我试过谷歌搜索,但到目前为止没有运气

回答by Steve Rindsberg

This should get you started:

这应该让你开始:

Sub ConvertAllShapesToPic()
    Dim oSl As Slide
    Dim oSh As Shape

    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.Shapes
            ' modify the following depending on what you want to
            ' convert
            Select Case oSh.Type
                Case msoChart, msoEmbeddedOLEObject, msoLinkedOLEObject
                    ConvertShapeToPic oSh
                Case msoPlaceholder
                    If oSh.PlaceholderFormat.ContainedType = msoEmbeddedOLEObject _
                        Or oSh.PlaceholderFormat.ContainedType = msoLinkedOLEObject _
                        Or oSh.PlaceholderFormat.ContainedType = msoChart _
                        Then
                        ConvertShapeToPic oSh
                    End If
                Case Else

            End Select
        Next
    Next

End Sub

Sub ConvertShapeToPic(ByRef oSh As Shape)
    Dim oNewSh As Shape
    Dim oSl As Slide

    Set oSl = oSh.Parent
    oSh.Copy
    Set oNewSh = oSl.Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)

    With oNewSh
        .Left = oSh.Left
        .Top = oSh.Top
        Do
            .ZOrder (msoSendBackward)
        Loop Until .ZOrderPosition < oSh.ZOrderPosition
    End With

    oSh.Delete

End Sub

回答by Santosh Sindham

Other quick alternative if you do not want to write a macro is to cut the object (Ctrl + x) and then paste it (Ctrl + v) as img (we can use paste special to select the image format or when we do a paste (Ctrl + v) MS power point will prompt with options to paste then select image in it). This way we need not have to save the image to a location on drive and then insert it back in the slide. Cut and Paste will work while being on the same slide.

如果您不想编写宏,其他快速替代方法是剪切对象 (Ctrl + x),然后将其 (Ctrl + v) 粘贴为 img(我们可以使用特殊粘贴来选择图像格式,或者当我们进行粘贴时(Ctrl + v) MS 电源点将提示粘贴选项,然后在其中选择图像)。这样我们就不必将图像保存到驱动器上的某个位置,然后将其插回幻灯片中。剪切和粘贴将在同一张幻灯片上工作。