【问题标题】:Positioning images on slides in PowerPoint 2007 using vba使用 vba 在 PowerPoint 2007 中的幻灯片上定位图像
【发布时间】:2014-12-27 22:17:28
【问题描述】:

我想在 Windows 上的 PowerPoint 2007 中做两件事之一。

首先是更改在图像中粘贴的默认位置。当我粘贴用 SAS 制作的图表时,它会粘贴到左上角。理想情况下,我想更改默认粘贴位置。似乎没有任何简单的选项,但我认为 VBA 可能是可能的。

如果不可能,那么我想编写一个 VBA 宏来逐步浏览每张幻灯片并更改图像位置。

感谢这个网站和其他网站(MsgBox 只是一个测试),我得到了一个幻灯片循环:

Sub SlideLoop()
    Dim osld As Slide

    For Each osld In ActivePresentation.Slides
        osld.Select
        MsgBox "The slide index of the current slide is: " & _
             ActiveWindow.View.Slide.SlideIndex
    Next osld

End Sub

除此之外,我运气不佳。我见过代码 sn-ps 选择幻灯片上的所有图像并裁剪或调整它们的大小,我在 excelhelphq.com 上找到了这个用于定位图像的位:

With ActiveWindow.Selection.ShapeRange
  .Left = 50 'change the number for desired x position
  .Top = 50 'change the number for desired y position
End With 

但我不确定如何将它集成到循环中,而且 Powerpoint VBA 的在线文档并不是特别强大。一些代码处理 ShapeIndex,但我不确定如何使用它。

我应该提到,当我有一张图片时,我在幻灯片上只有一张图片(不过,有些幻灯片根本没有图片)。

这似乎是最好的节省时间的方法,尽管我仍然首先手动粘贴到 PowerPoint 中。

感谢您对此提供的任何帮助!我找不到任何可以解决这个确切问题的东西。

用于 PPT 的 VBA 是否正在逐步淘汰?感觉就像微软不希望人们能够根据他们不出色的在线文档来弄清楚如何使用它。

【问题讨论】:

    标签: vba powerpoint powerpoint-2007


    【解决方案1】:

    MS 不太可能很快淘汰 VBA。如果他们这样做,太多的大公司客户会烤它们。尽管如此,你是对的,文档很糟糕,并且随着每个版本的发布而变得更糟。

    那么,让这样的地方更有价值。因此,首先对您的基本循环进行一些清理:

    Sub SlideLoop()
        Dim osld As Slide
    
        For Each osld In ActivePresentation.Slides
            ' osld.Select  No need to select a slide before acting on it
            'MsgBox "The slide index of the current slide is: " & _
            '     ActiveWindow.View.Slide.SlideIndex
            MsgBox "The slide index of the current slide is: " & cstr(osld.SlideIndex)
        Next osld
    
    End Sub
    

    所以这里是如何做你所追求的开始:

    Sub SlideLoop()
        Dim osld As Slide
        Dim oSh As Shape
    
        For Each osld In ActivePresentation.Slides
            ' check each shape on the slide
            ' is it an image or whatever you're looking for?
            For Each oSh In osld.Shapes
                With oSh
                    If .Type = msoLinkedPicture _
                    Or .Type = msoPicture Then
    
                    ' position it to taste
                    .Left = 100
                    .Top = 100
    
                    ' centering/resizing gets trickier
                    ' but is still possible.
                    ' Exercise for the reader?
                    ' Hint:
                    ' ActivePresentation.PageSetup.SlideWidth and .SlideHeight
                    ' tells you the width and height of the slide
                    '
                    ' All values are in Points (72 to the inch)
    
                    End If
                End With
            Next    ' Shape
        Next osld   ' Slide
    
    End Sub
    

    【讨论】:

    • 非常感谢史蒂夫!为了简单起见,我取出了 LinkedPicture 检查,否则效果很好。
    猜你喜欢
    • 1970-01-01
    • 2019-11-10
    • 1970-01-01
    • 1970-01-01
    • 2015-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    相关资源
    最近更新 更多