使用vba在PowerPoint 2007中定位幻灯片上的图像
问题描述:
我想在Windows上的PowerPoint 2007中执行两项操作之一。使用vba在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
除此之外,我还没有多少运气。我所看到的代码段,选择一个幻灯片和作物所有图像或调整它们的大小,而且我发现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被淘汰了吗?这感觉就像微软不希望人们能够根据他们非常好的在线文档来弄清楚如何使用它。
答
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检查,不然的话,这可以很好地工作。 – jedmatic 2014-10-31 19:58:02