[英]VBA comparing files before moving to another folder
我一直在嘗試使用確保輸入和輸出文件夾匹配的代碼,然后再將輸入文件移動到另一個文件夾。 這是一個片段:
'Select first Excel file within that Outlook_ImportedClaimsFiles folder path
OutlookImportFN = Dir(OutlookImportPath & "\*.xls")
'Select first Excel file within the SAS_Outputs folder path
SASOutputFN = Dir(SASOutputsPath & "\*.xls")
'Cycle through all files in the source folder path until there are no more left to cycle through
Do While OutlookImportFN <> ""
Counter = Counter + 1
'Create full path name of the source file
sFilePathName = OutlookImportPath & "\" & OutlookImportFN
'Create full path name of the destination file and add the date and time the file was moved
dFilePathName = OutlookRunPath & "\" & Format(Now, "yyyymmdd") & "_" & OutlookImportFN
問題在於,在第一個文件夾(OutlookImportFN)中,有一個批處理/保存文件,其中包含該文件夾中所有文件的文件名,該文件名在整個過程中都使用。 標記第一個文件時,該文件首先出現(根本不應標記/選擇此文件)。 因此,進行比較時,文件不匹配(除非我從列表中的第二個文件開始)。 與輸出文件夾中的第一個文件比較時,如何從輸入文件夾中的第二個文件開始,或者在進行比較時如何跳過輸入文件夾中的此保留文件? 我已經嘗試了一些方法,但是似乎沒有任何效果。 預先感謝您的見解!
您需要添加一個If
語句,以確保該文件不是該批處理文件:
Do While OutlookImportFN <> ""
Counter = Counter + 1
If Not OutlookImportFN = "MyBatchFile" Then
'Create full path name of the source file
sFilePathName = OutlookImportPath & "\" & OutlookImportFN
'Create full path name of the destination file and add the date and time the file was moved
dFilePathName = OutlookRunPath & "\" & Format(Now, "yyyymmdd") & "_" & OutlookImportFN
End If
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.