是否可以使用With
語句的對象作爲從With
塊中調用的過程的參數,而無需完全限定該對象?它可能相當於this
或me
。將`With`語句的對象用作過程調用的參數
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
+1我問了自己同樣的問題無數次。雖然我害怕[我只對你有壞消息](http://stackoverflow.com/a/19700906/119775)。 –