VBA to pre-populate email

Hello Experts,

I am familiar with VBA for Excel.  Not in the sense that I write it myself, but I have received many pieces of code, that generally I can customize a few lines to fit my needs at the time.

As for Outlook and VBA - I'm totally lost!

I am hoping someone can supply me with some lines of code that will do the following steps.

1.)  Open new email
2.)  To:  johndoe@nobody.com
3.)  CC: janedoe@nobody.com
4.)  Subject: Sample Request
5.)  Body: (See below...)

Customer #:
Contact #:

Item #:
Qty:

I am hoping to view code for the above, and customize it further.  I'm sure I'll be posting more questions, cause my question is actually more advanced - but I figured I'll start here with the basics.

Thank you in advance for your help!

~ Geekamo
LVL 1
GeekamoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris BottomleySoftware Quality Lead EngineerCommented:
Assuming you want the code from Outlook then :

Sub Q_28227600_1()
Dim mai As MailItem
Dim str As String

    str = "Customer " & "CustName" & ":"
    str = str & vbCrLf & "Contact " & "ContactName" & ":"
    str = str & vbCrLf & vbCrLf
    str = str & "Item " & "ItemName" & ":"
    str = str & vbCrLf & "Qty " & "QuantityValue" & ":"
    str = str & vbCrLf & vbCrLf
    str = str & "I am hoping to view code for the above, and customize it further.  I'm sure I'll be posting more questions, cause my question is actually more advanced - but I figured I'll start here with the basics."
    str = str & vbCrLf & vbCrLf
    str = str & "Thank you in advance for your help!"
    str = str & vbCrLf & vbCrLf
    str = str & "~ Geekamo "
    Set mai = Application.CreateItem(olMailItem)
    With mai
        .To = "johndoe@nobody.com"
        .CC = "janedoe@nobody.com"
        .Subject = "Sample Request"
        .Body = str
        .Display
    End With

End Sub

Open in new window


Chris
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris BottomleySoftware Quality Lead EngineerCommented:
Note to automatically send the mail use .send instead of .display

Chris
0
GeekamoAuthor Commented:
@ chris_bottomley,

This code has worked out great - thank you!

~ Geekamo
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.