Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


August 2001

Back to Basics


RSS
Subscribe to Windows IT Pro | See More Visual Basic (VB) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

For example, this procedure would work fine as a toolbar macro:

Sub HelloWorld()
  MsgBox "Hello World!"
End Sub

But these wouldn't:

Private Sub HelloWorld()
  MsgBox "Hello World!"
End Sub

Public Sub Hello(strWho)
  MsgBox "Hello " & strWho
End Sub

Public Function Hello()
  strWho = _
    InputBox("Say hi to whom?")
  MsgBox "Hello " & strWho
  Hello = strWho
End Sub

To add a macro to the toolbar, choose View, Toolbars, Customize from the main Outlook menu. On the Commands tab in the Customize dialog box, select Macros from the Categories list. You'll see a list of macros on the right. Copy the desired macro to the toolbar or to an Outlook menu. Right-click the newly created toolbar button or menu command to customize the name, button, and other features.

Adjusting the Security Level
After you've written some VBA code, you might see a message when you start Outlook telling you that the macros can't run because of your security settings or asking you to authorize the macros. Outlook's macro security level determines which message you might see. You can change the security level on the Security dialog box that Figure 2 shows. From the main Outlook menu, select Tools, Macro, Security to open the dialog box.

If you want to use High security, you need to digitally sign your project, much as you might digitally sign an email message. Office 2000 includes the selfcert.exe file, which lets you create a self-signed certificate for signing projects. After you run this program and follow its prompts, you'll have a certificate that you can use to sign any VBA project. To use the self-signed certificate to sign your Outlook VBA project, choose Tools, Digital Signature in the VBA editor. If you don't see the Digital Signature command, you need to run Office Setup to install that option. For more details, read the Microsoft Developer Network (MSDN) article "How to Prevent the VBA Macro Security Warning in Microsoft Outlook 2000" (http://msdn.microsoft.com/library/techart/oldigitalsignature.htm). Note that Microsoft cautions that because no Certificate Authority (CA) backs the self-signed certificate, you should use it to sign only your personal VBA projects.

Ready to get started? Download some code samples and get going.

End of Article

   Previous  1  [2]  Next  


Reader Comments
Great article.

One comment. At the end of the article was written, "Ready to get started? Download some code samples and get going."

It would be really cool to have some good links where to find the code to download.

Tony Peterson October 25, 2002


Tony, this is just one of a series of articles on Outlook VBA coding. For the rest of the series, including sample code, visit <A HREF="http://www.winscriptingsolutions.com/Articles/Index.cfm?DepartmentID=83">http://www.winscriptingsolutions.com/Articles/Index.cfm?DepartmentID=83</A> .

Sue Mosher January 04, 2003


Hi
I am new to VBA programming, can tell me how you would open a web page in outlook, i have created the following macro and its works fine
but when the web page opens all the colour is missing and links don't work. How can you get the links to work and have the colours displayed.


Many Thanks

skandar



Sub Send_weather()
Send_Message "http://www.msn.com", "skandar@zetacontrols.co.uk"

End Sub


Private Sub Send_Message(xURL, email)
Dim objIE As Object
Dim objOL As New Outlook.Application
Dim objMail As MailItem

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate (xURL)

Do While objIE.Busy
Loop

Do While objIE.Document.ReadyState <> "complete"
Loop




Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
objMail.To = email
objMail.Subject = "From Street Map - " &
objIE.LocationName
'objMail.HTMLBody = objIE.Document.Body.innerHTML

objMail.HTMLBody = "<HTML></HTML>" &
objIE.Document.Body.outerHTML

'objMail.HTMLBody = "<HTML></HTML>"



objMail.Send
Set objMail = Nothing
Set objOL = Nothing
Set objIE = Nothing

End Sub

skandar taj February 10, 2003


This is JUST what I needed. Thank you!!

Jennifer February 14, 2003


This looks great! Thanks Sue.

mgamiet July 25, 2003


I am looking for a way to collect email accounts from a form that I have on my website.

My form sends me emails from customers who want to stay current with our software updtaes. Right now I recieve emails that I copy and paste adresses from. This worked ok at first, but now we are recieving such a high volume of requests that it has become a tedious endeavor.

Can I write a macro that will strip these email addresses out and write them to a text file. I am looking for a better alternative than what I have going right now.

Nate Balcom November 18, 2003


I want to add a button to my toolbar to do Find Related messages. It is possible to get this by adding the button in Outlook 2002 and then upgrading. However now I have a new Windows profile. Is there a way to add it from the mEnus or must I use a macro ?

Peter Young March 31, 2004


good article ..please tell me how to write macros for outlook ...please send me tutorials or the link of tutorials

vipul March 31, 2004


vipul, for more tutorials like this one, see http://www.outlookcode.com/d/vb.htm#tutorials

Sue_Mosher August 19, 2004 (Article Rating: )


For a great tutorial on practical, business uses of outlook try:

http://www.321books.co.uk/ebooks/outlook-vba-tutorial.htm

mal4mac September 17, 2004 (Article Rating: )


 See More Comments  1   2 

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Take Control of Your Email: Understand the Business Reasons for Email Storage Management

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

Bail Out Your Exchange Environment

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement