Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-23-2023, 04:43 AM
Ddadoo57 Ddadoo57 is offline Does anyone have a solution for displaying the generated email in the foreground? Windows 11 Does anyone have a solution for displaying the generated email in the foreground? Office 2021
Advanced Beginner
Does anyone have a solution for displaying the generated email in the foreground?
 
Join Date: Feb 2023
Posts: 73
Ddadoo57 is on a distinguished road
Default Does anyone have a solution for displaying the generated email in the foreground?

Hello everyone,

I have a Word VBA function that creates predefined emails with attachments.
Here are the main lines of the code:

...
Dim OutlookApp As Outlook.Application


Set OutlookApp = CreateObject("Outlook.Application")
...
Set fileDialog = Application.fileDialog(msoFileDialogFilePicker)
...
OutlookApp.Display
OutlookApp.ActiveInspector.Activate
...


My question: the generated email often remains in the taskbar, instead of being displayed large in the foreground, as it does when Outlook is or has been run at least once. The user doesn't always have the reflex to look in the taskbar to display the email, which causes confusion.

Does anyone have a solution for displaying the generated email in the foreground?

Best regards,
David
Reply With Quote
  #2  
Old 06-23-2023, 09:18 AM
gmayor's Avatar
gmayor gmayor is offline Does anyone have a solution for displaying the generated email in the foreground? Windows 10 Does anyone have a solution for displaying the generated email in the foreground? Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Code I have posted previously, displays the message. Note the link at the top for the function to open Outlook correctly.

Code:
Sub Send_As_Mail_Attachment()
'Graham Mayor = http://www.gmayor.com
'Send the document as an attachment _
  in an Outlook Email message
'Requires the code from - http://www.rondebruin.nl/win/s1/outlook/openclose.htm
'to either retrieve an open instance of Outlook or open Outlook if it is closed.
Dim bStarted As Boolean
Dim OlApp As Object
Dim oItem As Object
Dim oDoc As Document
Dim strName As String
Dim strDocName As String
Dim strPath As String
Dim intPos As Integer
Dim iFormat As Long
    Set oDoc = ActiveDocument
    'Prompt the user to save the document
    On Error GoTo Err_Handler:
    oDoc.Save
    strDocName = oDoc.Name
    iFormat = MsgBox("Send as PDF format?", vbYesNoCancel)
    If iFormat = 2 Then GoTo lbl_Exit
    If iFormat = 7 Then strDocName = oDoc.FullName: strName = oDoc.Name
    If iFormat = 6 Then
        'Get the document name and path
        strPath = oDoc.path & "\"
        intPos = InStrRev(strDocName, ".")
        strDocName = Left(strDocName, intPos - 1)
        strName = strDocName & ".pdf"
        strDocName = strPath & strDocName & ".pdf"

        'And save the document as PDF
        oDoc.ExportAsFixedFormat OutputFileName:=strDocName, _
                                 ExportFormat:=wdExportFormatPDF, _
                                 OpenAfterExport:=False, _
                                 OptimizeFor:=wdExportOptimizeForPrint, _
                                 Range:=wdExportAllDocument, From:=1, To:=1, _
                                 Item:=wdExportDocumentContent, _
                                 IncludeDocProps:=True, _
                                 KeepIRM:=True, _
                                 CreateBookmarks:=wdExportCreateHeadingBookmarks, _
                                 DocStructureTags:=True, _
                                 BitmapMissingFonts:=True, _
                                 UseISO19005_1:=False

        'Now close the document without saving as we have finished with it
        oDoc.Close 0
    End If
    'Get Outlook if it's running
    Set OlApp = OutlookApp()
    On Error GoTo 0
    'Create a new mailitem
    Set oItem = OlApp.CreateItem(0)

    With oItem
        .Subject = strName
        .attachments.Add strDocName
        .Display
    End With

lbl_Exit:
    Set oItem = Nothing
    Set OlApp = Nothing
    Exit Sub
Err_Handler:
    Err.Clear
    GoTo lbl_Exit
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 06-24-2023, 05:22 AM
Ddadoo57 Ddadoo57 is offline Does anyone have a solution for displaying the generated email in the foreground? Windows 11 Does anyone have a solution for displaying the generated email in the foreground? Office 2021
Advanced Beginner
Does anyone have a solution for displaying the generated email in the foreground?
 
Join Date: Feb 2023
Posts: 73
Ddadoo57 is on a distinguished road
Default

Thank you so much Graham Mayor!!!
I'll have a look and test it all!
Have a nice day,
David
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Focus a new Document and bring it in the foreground f__s Word VBA 0 04-27-2020 03:36 PM
Email Displaying Duplicates camilleislife Outlook 0 06-12-2017 12:14 PM
Does anyone have a solution for displaying the generated email in the foreground? how to keep a presentation allways on the foreground kuyperlu PowerPoint 1 06-22-2016 06:23 AM
How do I add a CC to an externally generated Email ? vodkasoda Outlook 8 01-26-2016 02:50 PM
email solution for Excel 2003 Kat Excel 0 06-29-2010 04:10 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:29 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft