讓我在Office 2003上寫的VBA在移轉至Office 2007時,產生莫大困擾。
之後決定用VB的 Dir函數來取代
原碼:
With Application.FileSearch
.LookIn = sPaht
.Filename = sDate & "*.TAB"
Select Case .Execute
Case Is > 1
esc = 1
MsgBox "檔案有重複!" & Chr(10) & "請確認路徑 " & .LookIn, vbCritical
Case 0
esc = 1
MsgBox "找不到檔案!" & Chr(10) & "請確認路徑 " & .LookIn, vbCritical
Case Else
sFilename = .FoundFiles(1)
End Select
End With
以Dir改寫:
If Dir(sPath & "\" & sDate & "*.TAB") <> "" Then
If Dir <> "" Then
esc = 1
MsgBox "檔案有重複!" & Chr(10) & "請確認路徑 " & sPath, vbCritical
Else
sFilename = sPath & "\" & Dir(sPath & "\" & sDate & "*.TAB")
End If
Else
esc = 1
MsgBox "找不到檔案!" & Chr(10) & "請確認路徑 " & sPath, vbCritical
End If
End With
沒有留言:
張貼留言