本文介绍了如何在 Powerpoint 中使用 VBA 宏检查文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行我的代码之前检查文件是否已经存在.如果存在则退出,否则保持我的代码运行.我写的是以下代码:

I want to check if a file already exist before running my code. If it exists than exit otherwise keep my code running. What I wrote is following code:

Private Sub CommandButton21_Click()

If FileFolderExists("C:\Users\Moez\Desktop\Macro_Project\Test1.pptm") Then
    MsgBox "Modification already done!"
Else
    deleteTextBox
    AllBlackAndDate
    LastModifiedDate
    SaveAllPresentations "C:\Users\Moez\Desktop\Macro_Project\Test1.pptm" ' save here
End If

End Sub          

推荐答案

如果要检查本地计算机上是否存在文件,则要使用 FileSystemObject.

If you want to check a file exists on the local machine you want to use a FileSystemObject.

Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")

if fso.FileExists("Your file name and path here") Then
    ' do what you like in the case where the file exists
Else
    ' do whatever you wanted to do where the file doesn't exist
End If

如果您需要任何进一步的解释,请告诉我.

Let me know if you need any further explanation.

这篇关于如何在 Powerpoint 中使用 VBA 宏检查文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:41