使用`With`语句的对象作为过程调用的参数 [英] Using the object of a `With` statement as parameter for a procedure call
问题描述
可以使用对象使用
语句作为从中调用的过程的参数与
阻止,而不必完全限定该对象?这可能相当于这个
或我
。
使用thisThing.thatThing.otherThing.myObject
MySub [?]'如何指定myObject作为参数?
MySub这个不,不是吧...
MySub我不是这样吗?
'当然我可以这样做:
MySub thisThing.thatThing.otherThing.myObject
'但是我宁愿不必像我这样
....
结束
示例:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b结束与
<范围与>
将指代 Worksheet.Range(A1)
编辑:
看起来我只是提供一个单一的范围,我的坏的单一价值。我专门试图解析一下我所调用的程序(它在指定范围内绘制一些边框)。
我的实际代码:
With ReportSheet
//调用drawBorder(.Range(.Cells(j + 9,2),.Cells(k + 9,2)))< - 我现在要做的是
用.Range(.Cells(j + 9,2),.Cells(k + 9,2))
/ / call drawBorder(<指定的范围>< - 我想要做的
//其他代码
结束
结束
Sub drawBorder (drawRange As Range)
带drawRange
//各种代码
结束
End Sub
您可以使用
drawBorder .Cells
注意:不需要使用调用
自己的 Sub
名称后跟无括号参数就足够了
Is it possible to use the object of a With
statement as parameter for a procedure called from within a With
block, without having to fully qualify that object? It could be the equivalent of a this
or 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
Example :
With Worksheet.Range("A1:E4")
Call SubName(<range from with>)
End With
<range from with>
would be referring to Worksheet.Range("A1")
Edit:
Seems that I was implying a single value by giving a range of just a single cell range, my bad. I'm specifically trying to parse a range into the procedure that I'm calling (it draws some borders around the specified range).
My actual code:
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
You can use
drawBorder .Cells
Note: no need to use Call
, the Sub
name on its own followed by unbracketed parameters is sufficient
这篇关于使用`With`语句的对象作为过程调用的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!