軟體:excel
版本:任何版本
If (MsgBox("是否執行取代?", vbYesNo) = vbNo) Then Exit Sub
Application.ScreenUpdating = False '巨集執行時不更新螢幕
Dim openfile$, filepath$, thiswrkname$
Dim FileChosen As Integer
Dim ff As String
Dim MM
Dim diaFolder As FileDialog
thiswrkname = ThisWorkbook.Name
'開啟資料夾
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
fd.AllowMultiSelect = False
FileChosen = fd.Show
'沒有選資料夾離開程式
If FileChosen <> -1 Then
MsgBox "你沒有選擇資料夾"
Exit Sub
Else
filepath = fd.SelectedItems(1) & "\"
End If
openfile = Dir(filepath & "*.xls*")
Application.DisplayAlerts = False
'資料夾沒檔案離開程式
If openfile = "" Then
MsgBox "資料夾內沒有要處理檔案,請確認"
Exit Sub
End If
====
主要是下面這段:
'