繁体   English   中英

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

[英]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.

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