EXCEL的搜索扩展-图形中搜索

原创: 牛超

2009-06-04

OSAKA

 

EXCEL本身的搜索功能有限,如何定位到图形中的文字,工作中的问题。

试验了半天,解如下:

 

'find string from shapes in the worksheets with diagrams Function findInShape(str As String, Optional ByVal sel As Boolean = False) As String() Dim strret(1) As String Dim strget, strtmp, strdd As String strret(0) = "" strret(1) = "" strtmp = "" strget = "" For Each ws In ThisWorkbook.Worksheets If ws.Index < 4 Then GoTo ConOuter End If For Each sh In ws.Shapes 'strshow = strshow + sh.AlternativeText On Error GoTo ConInner cnt = cnt + 1 'whether the shape type is AutoShape If sh.Type = msoAutoShape Then 'key process: get description from this AutoShape 'in order to skip line shape If Len(sh.AlternativeText) > 0 Then strget = sh.TextFrame.Characters.Caption If InStr(strget, str) <> 0 Then strtmp = sh.TopLeftCell.Address(False, False) If sel Then 'Ok , activate it! ws.Activate sh.TopLeftCell.Select sh.TopLeftCell.Activate 'continue ? If MsgBox(ws.Name + "!" + strtmp, vbOKCancel, "continue search?") = vbCancel Then Exit Function End If End If strret(0) = strret(0) + strget + ";" strret(1) = strret(1) + ws.Name + "!" + strtmp + ";" 'Exit For End If End If End If ConInner: Next ConOuter: Next If Len(strret(0)) > 0 Then strret(0) = Left(strret(0), Len(strret(0)) - 1) strret(1) = Left(strret(1), Len(strret(1)) - 1) Else strret(0) = "-" strret(1) = "-" End If findInShape = strret End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值