Avatar of Frank Freese
Frank Freese
Flag for United States of America asked on

VBA for Outlook

Good morning folks,
This is a VBA Outlook need. In searching the Internet for Outlook VBA examples I haven't found an example of what I would like to do.
I send a lot of emails to myself so when I go to the To: selection or Copy: selection I have to type in my email address. Is it possible to have code that will allow me to click on To or Copy then using the short-cut menu click on an option to add my email address with having to type it in all the time? I would be interested to see what the code looks like. I use Outlook 2016 and have not even located a publication for VBA Outlook programming.
OutlookVBA

Avatar of undefined
Last Comment
Darrell Porter

8/22/2022 - Mon
Bill Prew

Once you have entered your email address in the To field on one message Outlook should add that to the "nicknames" that it stores, and the next time you send a message and are in the To field and type the first letter or two of your email address it should drop down a list of matching emails where you can select yours.  That feels probably as easy as trying to map a keyboard shortcut to it, which Outlook doesn't support very well.

If you really want to just click a key combo and have your email filled in then I might look outside Outlook, at a keyboard automation tool.  I purchased KeyText a while back and use it for some similar tasks, but it isn't free.  There are others though, a few mentioned below but Google will probably find you more...



»bp
Frank Freese

ASKER
Thanks Bill. I will consider your suggestions, however, and it may not be possible with VBA for Outlook
Darrell Porter

Why not have a desktop shortcut with a key assignment which runs the following command:
"C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE" /c IPM.note /m email@address.com

Open in new window


You can then press the key combination you assign to the shortcut and, as long as Outlook is already open, a window with a new message addressed to you at mail@address.com will appear.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Frank Freese

ASKER
Let me chew on this - interesting
Darrell Porter

In the event you want a VBA Macro you can put on the Ribbon, use the following code
Public Sub NotesToMyself()
  Set OL = CreateObject("Outlook.Application")
  Set EmailItem = OL.CreateItem(olMailItem)
  Set olNS = OL.GetNamespace("MAPI")
  tofield = olNS.Accounts.Item(1).SmtpAddress
    With EmailItem
      .Subject = "Note To Self"
      .Body = "[Enter your message here]" & vbCrLf & _
      "" & vbCrLf & _
      .To = tofield
      .Importance = olImportanceNormal
      .Send
  End With
End Sub

Open in new window


The top 4 lines determine your email address and it is inserted at the .To = tofield so the code can be shared with others without hard-coded email addresses.
Frank Freese

ASKER
Darrel,
I copy and pated your code to a new procedure. However, in attempting to run it I get the following error:
Notes to MyselfCould use a little hep here, please.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Bill Prew

This link provides info on enabling macros in Outlook.

How to enable and disable macros in Outlook?


»bp
Frank Freese

ASKER
Darrel,
Have you tested this code. I get all types of problem. I do have Option Explicit enabled.
ASKER CERTIFIED SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Frank Freese

ASKER
Thanks to all. Bill, I can now study this code. Appreciate everyone
Your help has saved me hundreds of hours of internet surfing.
fblack61
Bill Prew

Welcome Frank, hope you get something that works well for you.


»bp
Darrell Porter

Bill, nice work!  I literally just hacked something together from toilet paper and white glue and you polished it into something splendid.  Thank you!