當前位置:成語大全網 - 新華字典 - 如何用VBA建立查詢,打開指定文件夾內對應名稱的文件

如何用VBA建立查詢,打開指定文件夾內對應名稱的文件

Sub GetFolder()

Dim FolderName, FileName, MyFolder, MyFile As String

FolderName = "abc"

FileName = "abc.xls"

MyFolder = Dir("D:\" & FolderName, 16)

MyFile = Dir("D:\" & FolderName & "\" & FileName, 16)

If MyFolder <> "" Then

MsgBox "The folder is OK"

Else

MkDir "D:\" & FolderName

End If

If MyFile <> "" Then

MsgBox "The File is OK"

Else

Open "D:\" & FolderName & "\" & FileName For Output As #1

Close #1

End If

End Sub