Solved

How to get Outlook hand control back to Excel VBA procedure?

Posted on 2016-10-22
4
44 Views
Last Modified: 2016-11-11
I have an Excel VBA procedure that sends emails from am Outlook Template (.oft). That works fine.
I'd like to put at the top of the process a .Display so that the template is displayed for the user to check that it is the correct one.

Is it possible to make the Excel VBA to continue running when the user Closes the displayed Outlook template? I think this would need something like the 'close' in Outlook triggering a procedure in Excel. Would that be possible?

Thanks
0
Comment
Question by:hindersaliva
  • 2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:xtermie
ID: 41856647
Can you provide a snippet of your code so we can understand better?
0
 

Author Comment

by:hindersaliva
ID: 41856655
This displays the template. OK.

Sub PreviewEmails()

    Dim myOlApp As Outlook.Application
    Dim oMail As Outlook.MailItem
    Set myOlApp = CreateObject("Outlook.Application")
    
    strTemplateName = "Template1"
    strTemplateFolder = "C:\Samples\Sending emails\"
    strPath = strTemplateFolder + strTemplateName
    
    Set oMail = myOlApp.CreateItemFromTemplate(strPath)

    oMail.Display

End Sub

Open in new window


My question is, when the user closes the displayed template (with close box) is it possible for that event to run/call an Excel VBA procedure?
0
 
LVL 17

Accepted Solution

by:
xtermie earned 500 total points
ID: 41878529
If you want to run the macro when the template window is closed by the user, you probably need to create an API hook to the close button click, as explained here http://www.codeproject.com/KB/system/CSLLKeyboard.aspx?msg=2052655
You need to hook WM_CLOSE, WM_DESTOY or WM_QUIT of your template window to your macro
0
 

Author Comment

by:hindersaliva
ID: 41884165
Hi xtermie, I shall need to learn more about that. Thanks. I'll close the question.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
Read this checklist to learn more about the 15 things you should never include in an email signature.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now