是否可以将With
语句的对象用作从With
块内调用的过程的参数,而不必完全限定该对象?可能等于this
或me
。
With thisThing.thatThing.otherThing.myObject
MySub [?] ' How do I specify myObject as the parameter?
MySub This 'No, that's not it...
MySub Me 'Not this either... what is it?
'Of course I could do this:
MySub thisThing.thatThing.otherThing.myObject
'But I'd prefer not having to fully qualify myObject like that
....
End With
范例:
With Worksheet.Range("A1:E4")
Call SubName(<range from with>)
End With
<range from with>
指的是 Worksheet.Range("A1")
编辑:
似乎我只是通过提供单个单元格范围的范围来暗示单个值,这很糟糕。我正在专门尝试将范围解析为我正在调用的过程(它在指定范围周围绘制了一些边界)。
我的实际代码:
With ReportSheet
// Call drawBorder(.Range(.Cells(j + 9, 2), .Cells(k + 9, 2))) <--What I have to do right now
With .Range(.Cells(j + 9, 2), .Cells(k + 9, 2))
//Call drawBorder(<the specified range above> <--What I want to do
//Other code
End With
End With
Sub drawBorder(drawRange As Range)
With drawRange
//Various code
End With
End Sub
您可以使用
drawBorder .Cells
注意:无需使用Call
,仅使用Sub
名称后跟无括号的参数即可
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句