【问题标题】:Powerpoint VBA to insert images based on a file path contained in the slidePowerpoint VBA 根据幻灯片中包含的文件路径插入图像
【发布时间】:2014-07-11 07:25:39
【问题描述】:

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

【问题讨论】:

  • 不要索要代码。自己做一些工作,如果这还不够,那么来这里寻求代码方面的帮助。没有人愿意为您完成所有工作。
  • 不需要代码,只要指向正确的方向。我只是想了解是否有可能做到这一点。如果没有,那么我可以稍微不同地设置报告。

标签: vba powerpoint


【解决方案1】:

只需将以下代码剪切在一起: 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    相关资源
    最近更新 更多