標題:
內容為excel 2003的程式碼,請問各位大大如在2010版本該如何修改,謝謝
[打印本頁]
作者:
aaronprada
時間:
2012-12-30 19:02
標題:
內容為excel 2003的程式碼,請問各位大大如在2010版本該如何修改,謝謝
Public Sub FileSearch(Target)
'檔案搜尋用副程式
'With Application.FileSearch
Application.FileSearch.NewSearch
Application.FileSearch.LookIn = "E:\"
Application.FileSearch.SearchSubFolders = True
Application.FileSearch.Filename = Target
Application.FileSearch.MatchTextExactly = True
Application.FileSearch.FileType = msoFileTypeAllFiles
If Application.FileSearch.Execute() = 1 Then
Filegot = Application.FileSearch.FoundFiles(1)
Exit Sub
Else
If Application.FileSearch.Execute() = 7 Then: Exit Sub
If InStr(Target, "警報記錄.csv") > 0 Then: MsgBox "請將當日環控原始檔案放入光碟機" & vbCrLf & vbCrLf & "或確認 7 個環控原始檔名正確": End
MsgBox "光碟內找不到或有兩個以上 " & Target & ",請指定檔案位置"
Filegot = Application.GetOpenFilename(UCase(Right(Target, 3)) & " Files (*" & Right(Target, 4) & "),*" & Right(Target, 4)) '手動取檔
If InStr(Filegot, Replace(Left(Target, Len(Target) - 4), "*", "")) = 0 Then: MsgBox "檔案選擇錯誤" & vbCrLf & vbCrLf & "請選擇" & Target: End
'End With
End Sub
作者:
Hsieh
時間:
2012-12-30 21:24
Public Sub FileSearch(Target)
fd = "E:\" '指定光碟機
Filegot = Dir(fd & "*" & Target & "*") '找出含有Target之檔案名稱
Do Until Filegot = ""
cnt = cnt + 1 '計算類似檔名個數
Filegot = Dir
Loop
If cnt = 1 Then
If InStr(Target, "警報記錄.csv") > 0 Then: MsgBox "請將當日環控原始檔案放入光碟機" & vbCrLf & vbCrLf & "或確認 7 個環控原始檔名正確": End
Else
MsgBox "光碟內找不到或有兩個以上 " & Target & ",請指定檔案位置"
Filegot = Application.GetOpenFilename(UCase(Right(Target, 3)) & " Files (*" & Right(Target, 4) & "),*" & Right(Target, 4)) '手動取檔
If InStr(Filegot, Replace(Left(Target, Len(Target) - 4), "*", "")) = 0 Then: MsgBox "檔案選擇錯誤" & vbCrLf & vbCrLf & "請選擇" & Target: End
End If
End Sub
複製代碼
回復
1#
aaronprada
試試看
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)