A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

.Display does not work when Outlook has not been started yet



 
 
Thread Tools Search this Thread Display Modes
  #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


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

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 10:40 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.