【问题标题】:checking if a file already exist using VBA powerpoint使用 VBA PowerPoint 检查文件是否已存在
【发布时间】:2016-11-08 11:48:01
【问题描述】:

我想检查 A FileName 是否已经存在。当我在本地桌面上测试它时,我写的东西非常有效。但是所有文件名都保存在一个 Sharepoint 中。当我在那里测试它时,它不起作用!我总是收到错误消息:bad file Name or number. 这是我写的:

Private Sub CommandButton21_Click()

Dim NewFileName             As String
Dim OwnPathName             As String

oldWeekDay = Weekday(Now)

Select Case oldWeekDay

Case 1
    NewFileName = "PT PM Weekly " & Format(Date + 4, "yyyymmdd")
Case 2
    NewFileName = "PT PM Weekly " & Format(Date + 3, "yyyymmdd")
Case 3
    NewFileName = "PT PM Weekly " & Format(Date + 2, "yyyymmdd")
Case 4
    NewFileName = "PT PM Weekly " & Format(Date + 1, "yyyymmdd")
Case 5
    NewFileName = "PT PM Weekly " & Format(Date, "yyyymmdd")
Case 6
    NewFileName = "PT PM Weekly " & Format(Date + 6, "yyyymmdd")
Case 7
    NewFileName = "PT PM Weekly " & Format(Date + 5, "yyyymmdd")

End Select

OwnPathName = ActivePresentation.Path
FullFileName = OwnPathName & "\" & NewFileName

'for debug only (can remove it later)
'MsgBox OwnPathName
'MsgBox FullFileName


 Dim StrFile             As String
 Dim FileFound           As Boolean

 FileFound = False
 'look for all types of PowerPoint files only (filter only to PowerPoint files to save time)
 StrFile = Dir(OwnPathName & "\*pptm*")

 Do While Len(StrFile) > 0
 If InStr(StrFile, NewFileName) > 0 Then
    FileFound = True
    Exit Do
End If
StrFile = Dir
Loop

If FileFound Then
MsgBox "Modification already done"
Else
RemoveTextboxes
AllBlackAndDate
SaveAllPresentations (FullFileName)
End If

End Sub

我不明白为什么它不起作用! 你能帮我解决问题吗? 提前致谢!

【问题讨论】:

标签: vba macros powerpoint


【解决方案1】:

我认为这可能有效,我一直使用它来循环访问我的 PC 或任何我可以访问的网络上的目录。

F = Dir(StrFile, 7)  'sets f equal to the first file name
Do While F <> ""        'loops until there are no more files in the directory

 If InStr(StrFile, NewFileName) > 0 Then
    FileFound = True
    Exit Do
 End If  

  F = Dir            'set f equal to the next file name in the directory

Loop

【讨论】:

    猜你喜欢
    • 2017-02-21
    • 2012-07-19
    • 2013-04-27
    • 1970-01-01
    • 2020-10-19
    • 2017-11-10
    • 1970-01-01
    • 2019-04-29
    • 1970-01-01
    相关资源
    最近更新 更多