?
Solved

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

Posted on 2016-10-22
4
Medium Priority
?
72 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

764 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