View Single Post
  #1  
Old January 9th 08, 08:09 PM posted to microsoft.public.outlook.program_vba
BigBirdNL
external usenet poster
 
Posts: 2
Default .Display does not work when Outlook has not been started yet

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


Ads