Nested with hiearchy expression

I met this several times recently, and I was just curious if there was an easier way to do this ...

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

Should it be completely written out, or is there a way to notify him, which makes it easier / cleaner? Perhaps there is some way or way to transfer yourself only for this instance? What about referencing a property or method from a higher c?

SomeFunctionAnswer =  SomeFunction .Self  '???
'OR
SomeFunctionAnswer =  SomeFunction .Parent.Name  '???

Hope this makes sense ...

+4
source share
3 answers

The answer is simple and simple. No No.

With , . , .

, With, . With With.

, , , .

+5

, , :

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
0

You can pull it out of internal and external. You can then opt out of the Activeworkbook qualification.

With Activeworkbook
  'Do Stuff
  With .Sheets(1)
    'More stuff Done
    '...
  End With
  SomeFunctionAnswer = SomeFunction .Sheets(1)
  'Yet more stuff Done
End With
0
source

Source: https://habr.com/ru/post/1667583/


All Articles