本帖最后由 kevinch 于 2011-8-29 13:52 编辑 Global $oExcelApp,$oExcel
$oExcelApp=ObjGet("","excel.application")
If IsObj($oExcelApp) Then
$oExcelApp.visible=True
If $oExcelApp.workbooks.count>0 then
For $oExcel In $oExcelApp.activeworkbook.worksheets
searchcell("test2")
Next
EndIf
EndIf
Func searchcell($sFindValue)
With $oExcel
$oRng=.usedrange.find($sFindValue)
If IsObj($oRng) Then
$oR=$oRng
Do
MsgBox(0,"GetColor",$oExcel.name&@TAB&$oR.address&@tab&$oR.offset(0,2).interior.color)
$oR=.usedrange.findnext($oR)
Until $oR.address=$oRng.address
MsgBox(0,"END","END")
EndIf
EndWith
EndFunc
改成这样,为了让你明白,再提供一组对应的vba代码,看后你会知道多明白一点的。Sub test()
Dim Ws As Worksheet, Rng As Range, R As Range
For Each Ws In Worksheets
If Not Ws.UsedRange.Find("test2") Is Nothing Then
With Ws
Set Rng = .UsedRange.Find("test2")
Set R = Rng
Do
MsgBox .Name & vbTab & R.Address & vbTab & R.Offset(, 2).Interior.Color, , ""
Set R = .UsedRange.FindNext(R)
Loop Until Rng.Address = R.Address
End With
End If
Next Ws
MsgBox "End", vbOKOnly, "End"
End Sub
|