【问题标题】:Macro to open all PPT files打开所有PPT文件的宏
【发布时间】:2014-01-30 00:50:15
【问题描述】:

我创建了以下宏来打开某个地图中的所有ppt文件

Sub openAllPPT()
    Dim strCurrentFile As String
    Dim strFileSpec As String

    strFileSpec = "C:\Documents and Settings\aa471714\Desktop\Nieuwe map*.ppt"
    strCurrentFile = Dir$(strFileSpec)

    While Len(strCurrentFile) > 0
          Presentations.Open (strCurrentFile)
          strCurrentFile = Dir$
    Wend

End Sub

当我运行它时,我确实看到任何东西打开了。有人知道我错过了什么吗?

【问题讨论】:

  • 试试Presentations.Open FileName:=strCurrentFile, WithWindow:=True
  • 确定循环输入了吗?尝试将路径添加到文件,因为 strCurrentFile 是文件名无路径
  • 你的代码已经过时了。尝试使用 FileSystemObject。另外,将 While..Wend 替换为 Do While..Loop

标签: vba powerpoint


【解决方案1】:

Dir 只返回文件名,而不是文件的完整路径。 试试这个:

Sub openAllPPT()

    Dim strCurrentFile As String
    Dim strFileSpec As String
    Dim strDirectory As String

    strDirectory = "C:\Documents and Settings\aa471714\Desktop\"
    strFileSpec = "Nieuwe map*.ppt"

    strCurrentFile = Dir$(strDirectory & strFileSpec)

    While Len(strCurrentFile) > 0
          'Presentations.Open (strDirectory & strCurrentFile)
          Debug.Print strDirectory & strCurrentFile
          strCurrentFile = Dir$
    Wend

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多