Powerpoint VBA基于幻灯片中包含的文件路径插入图像

时间:2014-07-10 22:10:05

标签: vba powerpoint

我每个月都会制作一份冗长的powerpoint报告。每张幻灯片都有一个文本框,其中包含指向不同图像文件的文件路径。是否有一个简单的VBA可以引用这些文件路径,并用相关的图像替换它们?任何支持感激不尽。

1 个答案:

答案 0 :(得分:0)

将代码拼凑起来: http://social.msdn.microsoft.com/Forums/en-US/245c1ee3-0731-4ef5-b934-fea5291b3b7b/vba-how-do-i-pass-the-text-in-a-powerpoint-text-box-into-a-variable-in-excel?forum=isvvba http://support.microsoft.com/KB/168649

我不知道你是如何运行的,所以我没有将它包含在sub中,但你仍然需要更改要打开的演示文稿以及正确的幻灯片和形状。我建议将其放在Module中,并传递slideNo As Integer, shapeNo As Integer, fileName as String的参数。

Dim oPP As PowerPoint.Application
Dim oPPT As Presentation
Dim oShp As Shape
Dim sText As String

Set oPP = New PowerPoint.Application

Set oPPT = ActivePresentation
Set oPPT = oPP.Presentations.Open("c:\sample.ppt")

Set oShp = oPPT.Slides(1).Shapes(3)

sText = oShp.TextFrame.TextRange.Text

Dim oSlide As Slide
Dim oPicture As Shape

ActiveWindow.View.GotoSlide 1

Set oSlide = ActiveWindow.Presentation.Slides(1)

Set oPicture = oSlide.Shapes.AddPicture(sText, _
   msoFalse, msoTrue, 1, 1, 1, 1)
oPicture.ScaleHeight 1, msoTrue
oPicture.ScaleWidth 1, msoTrue

With ActivePresentation.PageSetup
  oPicture.Left = (.SlideWidth \ 2) - (oPicture.Width \ 2)
  oPicture.Top = (.SlideHeight \ 2) - (oPicture.Height \ 2)
  oPicture.Select
End With