Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
Please can anyone explain to me how to amend my code below to open outlook app on desktop before sending the report. If the Outlook Desktop App is not opened, the report would be in outbox until the day you open outlook on your desktop before it would send.
Sub mSendMail(pdfFilePath)
Dim objOutlk
Dim objMail
Const olMailItem = 0
' Create a new instance of Outlook application
Set objOutlk = CreateObject("Outlook.Application")
' Create a new mail item
Set objMail = objOutlk.createitem(olMailItem)
' Recipient's email address
objMail.To = "abcd@example.com"
' Subject of the email
objMail.Subject = "Testing " & Date()
' Body of the email
objMail.HTMLBody = "Body of the email, This is an automatic generated email from QlikView."
' Add attachment (use the generated PDF file)
objMail.Attachments.Add pdfFilePath
' Send the email
objMail.Send
' Release resources
Set objMail = Nothing
Set objOutlk = Nothing
End Sub
What should I add to open the desktop App if it has not opened?
Thanks.
@marcus_sommer thanks I got the solution from this link [RESOLVED] Stop / Starting Outlook via VBScript-VBForums . The code here that he was having issue with
Sub StartOutlook() Dim oShell set oshell = CreateObject("Wscript.Shell") oShell.run "cmd.exe /K ""C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE"" " End Sub
I modified the code a little bit and it does not open the command prompt at all but open Outlook strait away. The below is the full code for anybody that is looking for the similar solution:
You may try something like:
objOutlk.Visible = TRUE
which is a working approach by Excel.
If it doesn't work you will get here some ideas:
[RESOLVED] Stop / Starting Outlook via VBScript-VBForums
and here surely some more:
outlook vbs open - Google Suche
Beside this if you are performing these tasks in general with a logged user you may just manually open Outlook.
@marcus_sommer Thanks for the help. I did not know you have replied me here and I have sent another message to you on the former topic I opened "How to Use VB macros to send Email through Outlook in QlikView".
@marcus_sommer thanks I got the solution from this link [RESOLVED] Stop / Starting Outlook via VBScript-VBForums . The code here that he was having issue with
Sub StartOutlook() Dim oShell set oshell = CreateObject("Wscript.Shell") oShell.run "cmd.exe /K ""C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE"" " End Sub
I modified the code a little bit and it does not open the command prompt at all but open Outlook strait away. The below is the full code for anybody that is looking for the similar solution: