+ -
当前位置:首页 → 问答吧 → 如何判断word表格是否有某一个内容

如何判断word表格是否有某一个内容

时间:2011-01-05

来源:互联网

除了用表格遍历法,判断word单元格是否有某一数据。

作者: wl9643   发布时间: 2011-01-05

引用:
原帖由 wl9643 于 2011-1-5 13:13 发表
除了用表格遍历法,判断word单元格是否有某一数据。
Function TableInstr(oTable As Table, strTarget As String, Optional MatchWholeCell As Boolean = False, Optional MatchText As Boolean = False) As Boolean
    '''oTable:Word Table对象;MatchWholeCell:单元格匹配,默认为非单元格匹配;MatchText:是否区分大小写与全半角,默认为忽略
    '''该函数由指定字符串与表格内容进行比较返回一个Boolean值
    Dim strTable As String
    strTable = oTable.Range.Text
    If MatchWholeCell = True Then
        strTarget = Chr$(7) & strTarget & Chr$(13) & Chr$(7)
        strTable = Chr$(7) & strTable
    End If
    TableInstr = (InStr(1, strTable, strTarget, IIf(MatchText = True, vbBinaryCompare, vbTextCompare)) > 0)
End Function

''''测试
Sub Test()
    Debug.Print TableInstr(Me.Tables(1), "x", False, False)
End Sub

作者: 守柔   发布时间: 2011-01-05

热门下载

更多