Results 1 to 3 of 3
  1. #1
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    The 'With' construct (A2003)

    Being a novice I remain puzzled by some of the VBA constructis. For example, below is a snippet of code by Hellen Feddema.

    With msg

    .Item = omsg

    .To = Item.BillingInformation

    .Subject = Item.CardData

    .Body = Item.Mileage

    .Send

    End With

    She is using the "With" construct. VBA help doesn't respond to a query on "With" (which seems odd being that it is used in code!)
    Anyway, can someone explain the syntax of the With/EndWith code? I notice that each entry inside With/End With begins with a period? What is the significance of the period?

    Pardon my ignorance and thanks for the help.

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: The 'With' construct (A2003)

    Chuck,

    The With statement is just a manner to have less to type and (for some) make the code more readable.

    With msg
    .Item = omsg
    .To = Item.BillingInformation
    .Subject = Item.CardData
    .Body = Item.Mileage
    .Send
    End With

    and

    msg.Item = omsg
    msg.To = Item.BillingInformation
    msg.Subject = Item.CardData
    msg.Body = Item.Mileage
    msg.Send

    are just the same. With the With statement you don't have to type msg in front of each line . Just the dot and VBA will know you mean msg as you define it in the line
    With msg
    It don't have to be in the front of the line.
    MyVariable = .Subject
    is also correct if it stand between With and End With and will be interpreted as
    MyVariable = msg.Subject.
    Francois

  3. #3
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: The 'With' construct (A2003)

    I sort of suspected that was the syntax, but I wasn't sure. Thanks for the explaination.

Posting Permissions

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