判定word中是否存在欲购买的耗材

用途:判断Excel中的关键词是否存在于word文档中 

Sub 判定word中是否存在欲购买的耗材()
Dim ce As Range
Dim wd As Object
Dim sh As Worksheet
Dim wb As Workbook
Dim doc As Object
    Set wd = GetObject(, "word.application") '获取word对象
    For Each doc In wd.documents
        If InStr(doc.Name, "项目卡") Then '根据目标word文档的名字中的关键字来获取目标word文档的内容;
            strA = wd.documents(doc.Name).Range.Text 'mydocName = doc.FullName
            Exit For
        End If
    Next
    num = ActiveSheet.Range("b65536").End(3).Row
    For Each ce In ActiveSheet.Range("b2:b" & num) '遍历Excel中耗材列;
        If InStr(strA, ce.Text) = 0 Then
            Debug.Print ce.Text & "未找到!"
        End If
    Next
    MsgBox "ok,已完成!"
End Sub

猜你喜欢

转载自blog.csdn.net/zhanglei1371/article/details/83239181