在电子表格中,我把原始代码放在了黄金上。但这不适用于它上面的按钮!你可以看看它并纠正我在哪里错过任何东西吗?
原始代码(效果很好!)
Option Explicit
Sub Move_Files()
Dim FSO As Object
Dim sFromDir As String
Dim sToDir As String
Dim sFile As String
Dim rSearch As Range
Dim rFound As Range
sFromDir = "C:\Users\Documents\File Logistics Tool\A\"
sToDir = "C:\Users\Documents\File Logistics Tool\B\"
Set FSO = CreateObject("scripting.filesystemobject")
Workbooks.Open "C:\Users\Documents\File Logistics Tool\Book.xlsx"
Set rSearch = Range("A2:A" & Range("A1048576").End(xlUp).Row)
sFile = Dir(sFromDir & "*.xml")
While sFile > ""
Set rFound = rSearch.Find(What:=Left(sFile, Len(sFile) - 4),
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False)
If Not rFound Is Nothing Then FSO.CopyFile Source:=sFromDir & sFile,
Destination:=sToDir & sFile
sFile = Dir
Wend
End Sub
这不适用于VBA按钮!
Private Sub MOVINGCOMMAND_Click()
Dim FirstQ As Integer
FirstQ = MsgBox("Are you ready to move those files?", vbYesNo + vbQuestion, "File Logistics Tool")
If FirstQ = vbYes Then
Call Move_Files
Else
MsgBox "Please insert a list of files in the Book Spreadsheet."
End If
MsgBox "PROCESS COMPLETED"
End Sub
___________________
Sub Move_Files()
Dim FSO As Object
Dim sFromDir As String
Dim sToDir As String
Dim sFile As String
Dim rSearch As Range
Dim rFound As Range
sFromDir = "C:\Users\jaewon.lee\Documents\File Logistics Tool\A\"
sToDir = "C:\Users\jaewon.lee\Documents\File Logistics Tool\B\"
Set FSO = CreateObject("scripting.filesystemobject")
Workbooks.Open "C:\Users\jaewon.lee\Documents\File Logistics Tool\Book.xlsx"
Set rSearch = Range("A2:A" & Range("A1048576").End(xlUp).Row)
sFile = Dir(sFromDir & "*.xml")
While sFile > ""
Set rFound = rSearch.Find(What:=Left(sFile, Len(sFile) - 4), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not rFound Is Nothing Then FSO.CopyFile Source:=sFromDir & sFile, Destination:=sToDir & sFile
sFile = Dir
Wend
End Sub
我一遍又一遍地看着它,但却无法弄明白。