![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
Thank you so much Graham Mayor!!!
I'll have a look and test it all! Have a nice day, David |
|
|
|
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 |
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 |