gpt4 book ai didi

vba - 使用 `With` 语句的对象作为过程调用的参数

转载 作者:行者123 更新时间:2023-12-01 19:22:18 25 4
gpt4 key购买 nike

是否可以使用 With 的对象语句作为从 With 中调用的过程的参数 block ,而不必完全限定该对象?它可能相当于 thisme .

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

注意:无需使用CallSub 名称本身后跟不带括号的参数就足够了

关于vba - 使用 `With` 语句的对象作为过程调用的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19698651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com