几天前有个朋友(simon)来信问“如果在PPT里边插入影音文件,如何在保存文件的时候将影音文件也保存出来?”

呵呵,以前我也没处理过,通过测试,发现问题的关键是如何知道影音文件的路径,通过分析,发现其实并不是很难,主要是以前没有注意LinkFormat对象,其实在MSDN中有如下的范例:

PowerPoint中的LinkFormat对象With ActivePresentation.Slides(1).Shapes(1)
PowerPoint中的LinkFormat对象    
If .Type = msoLinkedOLEObject Then
PowerPoint中的LinkFormat对象        
With .LinkFormat
PowerPoint中的LinkFormat对象            .SourceFullName 
= "c:\my documents\wordtest.doc"
PowerPoint中的LinkFormat对象            .AutoUpdate 
= ppUpdateOptionAutomatic
PowerPoint中的LinkFormat对象        
End With
PowerPoint中的LinkFormat对象    
End If
PowerPoint中的LinkFormat对象
End With

其中对SourceFullName 属性解释如下:

应用于示例特性返回或设置链接 OLE 对象的源文件的名称或路径。可读写。String 类型。

使用如下的代码测试了一下:

PowerPoint中的LinkFormat对象'<summary>
PowerPoint中的LinkFormat对象
    'Test过程就是在在幻灯片里边插入一个空白幻灯片
PowerPoint中的LinkFormat对象
    '然后在幻灯片中插入一个影片文件,然后查看Shape对象的LinkFormat对象的FullName属性就行了
PowerPoint中的LinkFormat对象
    '至于保存的时候如何处理,这个简单,你写一段宏就可以了
PowerPoint中的LinkFormat对象
    '剩下的自己发挥吧
PowerPoint中的LinkFormat对象'
</summary>
PowerPoint中的LinkFormat对象
Sub InsertAvi()
PowerPoint中的LinkFormat对象    ActiveWindow.Selection.SlideRange.Shapes.AddMediaObject(FileName:
="F:\clock.avi"Left:=239.625, Top:=149.625).Select
PowerPoint中的LinkFormat对象    ActiveWindow.Selection.Unselect
PowerPoint中的LinkFormat对象
End Sub
PowerPoint中的LinkFormat对象
PowerPoint中的LinkFormat对象
Sub ShowPath()
PowerPoint中的LinkFormat对象    
If Application.ActivePresentation.Slides(1).Shapes(1).MediaType = ppMediaTypeMovie Then
PowerPoint中的LinkFormat对象        
'关键是你理解一下LinkFormat对象
PowerPoint中的LinkFormat对象
        'LinkFormat.SourceFullName就是文件的保存路径
PowerPoint中的LinkFormat对象
        MsgBox Application.ActivePresentation.Slides(1).Shapes(1).LinkFormat.SourceFullName
PowerPoint中的LinkFormat对象    
End If
PowerPoint中的LinkFormat对象
End Sub


这些是在VBA里边测试的,通过了,我想最主要的就是这个LinkFormat.SourceFullName这句话了,其实simon的想法很好,因为如果PPT中的影音文件如果不保存的话,如果放到别的机器上,就不能正常播放了,AVI就变成了一个图片了,呵呵,所以还是有用的。

我想余下的最重要的就是Update这个方法了,如下:

For Each sld In ActivePresentation.Slides
    For Each sh In sld.Shapes
        If sh.Type = msoLinkedOLEObject Then
            sh.LinkFormat.Update
        End If
    Next
Next

通过这个修改绝对路径为相对路径,应该就不是问题了。

相关文章:

  • 2021-05-04
  • 2022-12-23
  • 2021-10-11
  • 2021-12-01
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-14
  • 2022-01-11
  • 2022-02-03
  • 2022-01-14
  • 2021-07-08
  • 2021-05-06
  • 2021-04-23
相关资源
相似解决方案