Link to home
Start Free TrialLog in
Avatar of Frank Freese
Frank FreeseFlag 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.
Avatar of Bill Prew
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
Avatar of Frank Freese

ASKER

Thanks Bill. I will consider your suggestions, however, and it may not be possible with VBA for Outlook
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.
Let me chew on this - interesting
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.
Darrel,
I copy and pated your code to a new procedure. However, in attempting to run it I get the following error:
User generated imageCould use a little hep here, please.
This link provides info on enabling macros in Outlook.

How to enable and disable macros in Outlook?


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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks to all. Bill, I can now study this code. Appreciate everyone
Welcome Frank, hope you get something that works well for you.


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