使用Dir(FileName)确定文件是否存在

时间:2019-11-20 13:17:50

标签: excel vba

我尝试使用Dir(FileName)来确定文件是否存在。但是,即使我使用以下代码提取了正确的文件名,Dir(FileName)也会返回空,无论该文件实际上是否存在于驱动器中。预先感谢您的帮助!

 Sub SetUpTable()

    Dim ws As Worksheet, fName As String, SNumber As String, fPath As String, wbName As String

    wbName = ActiveWorkbook.Name

    SNumber = Left(wbName, InStr(wbName, "_") - 1)

    fPath = ThisWorkbook.Path

    Set ws = ActiveSheet

    With ws    
            
            fName = fPath & "\" & SNumber & " Tbl " & .Name
            
            If Dir(fName) <> vbNullString Then
                FileExistsWarning.Show    
            Else:
                Call ConvertToPDF    
            End If
                
     End With

End Sub

0 个答案:

没有答案