是否可以将With
语句的对象用作从块内调用的过程的参数With
,而不必完全限定该对象?它可能相当于 athis
或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