如何使用Powerpoint中的VBA宏检查文件是否存在

时间:2016-10-12 13:21:34

标签: vba powerpoint powerpoint-vba

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

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          

3 个答案:

答案 0 :(得分:5)

如果要检查本地计算机上是否存在要使用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

如果您需要进一步解释,请与我们联系。

答案 1 :(得分:2)

这是我见过的最佳方式:

Sub test()

thesentence = InputBox("Type the filename with full extension", "Raw Data File")

If Dir(thesentence) <> "" Then
    MsgBox "File exists."
Else
    MsgBox "File doesn't exist."
End If

End Sub

在此信用:

Check if the file exists using VBA

答案 2 :(得分:1)

这是我检查是否存在某些内容的版本。包括一个测试子。这应该适用于任何VBA环境,包括PowerPoint。

@Component
public class CorsConfig implements Filter
{

@Override
public void init(FilterConfig filterConfig) throws ServletException
{}

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException
{
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    String method = request.getMethod();
    if(method.equals("OPTIONS") || method.equals("options"))
    {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
        response.setStatus(200);
        filterChain.doFilter(servletRequest, servletResponse);
    }
    else
    {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
        filterChain.doFilter(servletRequest, servletResponse);
    }
}

@Override
public void destroy()
{}

}