Solved

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

Posted on 2016-10-22
4
55 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 18

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 18

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

827 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