vba 检查一个文件夹中的文件在另一个文件夹中是否存在(不含扩展名)

Sub test()

Dim Mypath, MyName
Dim n As Integer
n = 0
Dim MyStr() As String, wz As Integer

Mypath = ThisWorkbook.Path & "\第三方2\"    ' 指定路径。
MyName = Dir(Mypath, vbDirectory)   '
Do While MyName <> ""
    If MyName <> "." And MyName <> ".." Then
            'Debug.Print MyName
            n = n + 1
            ReDim Preserve MyStr(n) '给动态数组重定义一个实际的大小
            
            MyName = StrReverse(MyName)
            wz = InStr(MyName, ".")
            MyName = Right(MyName, Len(MyName) - wz)
            MyName = StrReverse(MyName)
                        
            MyStr(n - 1) = Right(MyName, 7)
    End If
    MyName = Dir
Loop

Dim m As Integer
m = 0
Dim MyStr2() As String

Mypath = ThisWorkbook.Path & "\导出文件2\"    ' 指定路径。
MyName = Dir(Mypath, vbDirectory)   '
Do While MyName <> ""
    If MyName <> "." And MyName <> ".." Then
            'Debug.Print MyName
            m = m + 1
            ReDim Preserve MyStr2(m) '给动态数组重定义一个实际的大小
            
            MyName = StrReverse(MyName)
            wz = InStr(MyName, ".")
            MyName = Right(MyName, Len(MyName) - wz)
            MyName = StrReverse(MyName)
                        
            MyStr2(m - 1) = Right(MyName, 7)
    End If
    MyName = Dir
Loop

Dim i As Integer, j As Integer
For i = 0 To n - 1
    For j = 0 To m - 1
        If MyStr(i) = MyStr2(j) Then
        
            Exit For
        End If
    Next
    If j = m Then
        MsgBox ("SalesWareHouseOut_" & MyStr(i) & ".xml没有对应的药检码excel!")
    End If
Next

End Sub


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值