![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
Hi,
To send an attachment from excel VBA, I create an MailItem, attach a file and display the mail item for the user to be able to add a receipient. This works fine when Outlook has already been started. Though, when Oulook is not started, it askes for the profile I want to use, mentions that Word is used as email editor and crashes with "Run-time error '-1630519291 (9ed04005)': The operation failed." The debugger stops on the .Display method. How can I make this work even when Oulook is not started yet? My code: Sub SendByMail(cBevNr, cKorteOmschrijving, cBijlageFile) ' creates and sends a new e-mail message with Outlook ' requires a reference to the Microsoft Outlook 11.0 Object Library Dim OLF As Outlook.MAPIFolder, olMailItem As Outlook.MailItem Dim ToContact As Outlook.Recipient Set OLF = GetObject("", _ "Outlook.Application").GetNamespace("MAPI").GetDef aultFolder(olFolderInbox) Set olMailItem = OLF.Items.Add ' creates a new e-mail message With olMailItem 'Subject .Subject = cBevNr & ": " & cKorteOmschrijving ' message subject 'Mailbody ' the message text with a line break .Body = "Bijgesloten de bijlagen behorend bij bevinding " & cBevNr & Chr(13) 'Attachements .Attachments.Add cBijlageFile, olByValue, , _ "Attachment" ' insert attachment 'Confirmations .OriginatorDeliveryReportRequested = False ' delivery confirmation .ReadReceiptRequested = False ' read confirmation 'Display .Display End With Set ToContact = Nothing Set olMailItem = Nothing Set OLF = Nothing End Sub |
#2
|
|||
|
|||
![]()
Problem solved.
The problem occurred because I did not initialize Outlook. Below is the corrected code. Sub SendByMail(cBevNr, cKorteOmschrijving, cBijlageFile) ' creates and sends a new e-mail message with Outlook ' requires a reference to the Microsoft Outlook 11.0 Object Library Dim ol As Outlook.Application Dim OLF As Outlook.MAPIFolder Dim olItem As Outlook.MailItem Dim ToContact As Outlook.Recipient Set ol = CreateObject("Outlook.Application") Set OLF = GetObject("", _ "Outlook.Application").GetNamespace("MAPI").GetDef aultFolder(olFolderInbox) Set olItem = ol.CreateItem(olMailItem) With olItem 'Subject .Subject = cBevNr & ": " & cKorteOmschrijving ' message subject 'Mailbody ' the message text with a line break .Body = "Bijgesloten de bijlagen behorend bij bevinding " & cBevNr & Chr(13) 'Attachements .Attachments.Add cBijlageFile, olByValue, , _ "Attachment" ' insert attachment 'Confirmations .OriginatorDeliveryReportRequested = False ' delivery confirmation .ReadReceiptRequested = False ' read confirmation 'Display .Display End With Set ToContact = Nothing Set olItem = Nothing Set OLF = Nothing End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Display work hours correctly? | Kevin Bentley | Outlook - Calandaring | 2 | June 9th 14 02:54 PM |
Problem with work week display | דן | Outlook - Calandaring | 0 | August 29th 07 09:26 AM |
::: How To Display An All Day Event Into A Work Week or 5 Days Calendar ::: | [email protected] | Outlook - General Queries | 1 | July 12th 07 08:07 PM |
Display Work Hours Only and reduce cell size | martin gifford | Outlook - Calandaring | 1 | May 5th 07 12:35 PM |
how can i display task with my work week calendar | Adrienne | Outlook - Calandaring | 1 | February 24th 06 11:39 PM |