Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    With Statement Gotchas (VBA/Word/2003 SP2)

    In reading the With Statement Help file, I see the following caution;
    <hr> Note In general, it's recommended that you don't jump into or out of With blocks. If statements in a With block are executed, but either the With or End With statement is not executed, a temporary variable containing a reference to the object remains in memory until you exit the procedure<hr>
    My interpretation is that it is safe to call another procedure from within a With . . . End With statement. But I'm not quite certain.

    Any guidance will be most appreciated.
    Regards
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: With Statement Gotchas (VBA/Word/2003 SP2)

    That depends on how good your error handling is. If you call out to another procedure and it errors out without returning to the calling process, the End With will never be executed. Generally, a With...End With is for doing things directly to an object or its properties. One other gotcha that may or may not be in the help is calling into another routine that also uses a With...End With. It's always safer to End With before you call out to another routine.
    Charlotte

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: With Statement Gotchas (VBA/Word/2003 SP2)

    Thank you Charlotte
    With your phrasing, it's crystal clear.
    Regards
    Don

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •