全局选择任何PPT文件使用VBA

问题描述 投票:1回答:1

我创建了一个代码,从我的系统中选择一个PPT文件。但这是一个硬编码。如何创建全局代码而不是硬编码?我的代码如下:

Sub PPTTest()
  Dim PPT As Object

  Set PPT = CreateObject("PowerPoint.Application")

  PPT.Presentations.Open "D:\Us\70\Desktop\Shaon\BOD.pptx", , , False

  ' Note that the file name and the module
  ' name are required to path the macro correctly.
  PPT.Run "BOD.pptx!Module1.KillSpecificSlide"

 End Sub

如何在全球范围内进行此选择?

excel vba powerpoint python-pptx
1个回答
0
投票

以下是从我的一个Excel宏中获取的(不完整)示例:

Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogOpen)
With fldr
    .Title = "Select a File"
    .AllowMultiSelect = False
    .InitialFileName = ""
    If .Show <> -1 Then Exit Sub
    sItem = .SelectedItems(1)
End With
Set fldr = Nothing

sItem现在包含所选项目。在你的PPT.Presentations.Open电话中使用它。

注意:此代码仍必须位于MS-Office文件中(word,ppt,excel)。要使这样的宏“全局”,它必须在启动模板中。

您可以在Excel选项,信任中心,信任中心设置下找到或更改包含启动模板的启动位置(在Excel中,但可能也在ppt中)。

© www.soinside.com 2019 - 2024. All rights reserved.