Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If you don't know how to downgrade, my instructions below should be helpful.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

758 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