简体   繁体   English

VBA在移动到另一个文件夹之前比较文件

[英]VBA comparing files before moving to another folder

I have been trying to use a code that ensures that there is a match from the input and output folders before moving input files into another folder. 我一直在尝试使用确保输入和输出文件夹匹配的代码,然后再将输入文件移动到另一个文件夹。 Here is a snippet: 这是一个片段:

'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

The problem is that in the first folder (OutlookImportFN), there is a batch/holding file that contains the filenames for all the files in that folder that is used in the overall process. 问题在于,在第一个文件夹(OutlookImportFN)中,有一个批处理/保存文件,其中包含该文件夹中所有文件的文件名,该文件名在整个过程中都使用。 When flagging the first file, this file comes up first (this file shouldn't be flagged/selected at all). 标记第一个文件时,该文件首先出现(根本不应标记/选择此文件)。 Because of this, when doing the comparison, the files don't match (unless I start with the 2nd file in the list). 因此,进行比较时,文件不匹配(除非我从列表中的第二个文件开始)。 How do I either start with the 2nd file in the Input folder when comparing to the 1st file in the Output folder, or skip over this holding file in the Input folder when doing the comparison? 与输出文件夹中的第一个文件比较时,如何从输入文件夹中的第二个文件开始,或者在进行比较时如何跳过输入文件夹中的此保留文件? I've tried a few things but nothing seems to work. 我已经尝试了一些方法,但是似乎没有任何效果。 Thanks in advance for your insight! 预先感谢您的见解!

You need to add an If statement which makes sure the file isn't that batch file: 您需要添加一个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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM