• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 101
  • Last Modified:

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

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?

  • 2
  • 2
1 Solution
Can you provide a snippet of your code so we can understand better?
hindersalivaAuthor Commented:
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)


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?
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
hindersalivaAuthor Commented:
Hi xtermie, I shall need to learn more about that. Thanks. I'll close the question.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now