我最近碰过这几次,如果有更简单的方法可以做到这一点,我只是好奇...
strEcho='echo ${str:0:2}' # '${str:2}' if you want to skip the first two characters and keep the rest
bash -c "str=\"$strFull\";$strEcho;"
它是否必须完全写出来,或者是否有某种方式来表明它更容易/更清洁?也许有某种属性或方法可以为这个实例传递自己的东西?如何从较高的With?
引用属性或方法With Activeworkbook
'Do Stuff
With .Sheets(1)
'More stuff Done
'...
'But now I need to refer to or pass the Sheet in the last With Statement
SomeFunctionAnswer = SomeFunction Activeworkbook.Sheets(1)
End With
'Yet more stuff Done
End With
希望有道理......
答案 0 :(得分:10)
答案很简单,没有。
With
条款有助于访问其主题的成员和方法,但它没有提供任何参考主题本身的工具。如果需要,您必须完全写出对象的名称或通过其他方式引用它。
再次访问作为外部 With
子句主题的对象的方法和成员时,您需要完全命名它。内部With
,及其整个范围完全隐藏了外部With
。
因此,编写代码的方式是正确的方法。
答案 1 :(得分:0)
分配给变量可能更容易,但这里有一种方法:
With Activeworkbook
'Do Stuff
With .Sheets(1)
'More stuff Done
'...
'But now I need to refer to or pass the Sheet in the last With Statement
SomeFunctionAnswer = SomeFunction Sheets(.name)
End With
'Yet more stuff Done
End With
答案 2 :(得分:0)
你可以将它从内部移出并移入外部。然后你可以放弃Activeworkbook资格。
With Activeworkbook
'Do Stuff
With .Sheets(1)
'More stuff Done
'...
End With
SomeFunctionAnswer = SomeFunction .Sheets(1)
'Yet more stuff Done
End With