Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Outlook form VB

Status
Not open for further replies.

TSO456

Technical User
Jul 23, 2001
57
US
Hello,

I would like to be able outlook from a control in VB. Can some one please provide me with the VB code.

Thanks

Jill
 
Hi Jill,

Sorry I'm having trouble understanding, but so you want to send an email through VB or just open outlook.

If all you want to do is open the outlook program than this will do it.
[tt]
SHELL("Outlook.exe")
[/tt]
If you want to send an email, then check in the FAQ's there are a lot of helpful hints in there. Craig, mailto:sander@cogeco.ca

Si hoc legere scis, nimis eruditionis habes
 
Craig

I meant to say that I would like to launch an outlook email from a VB application. For example on click launch Outlook and attach a particular file.

Thanks
Jill
 
The following may help with your question though includes references to controls on other form for the attachemnts. Hope this helps.

Option Explicit
Public OlApp As Outlook.Application
Public eMsg As Outlook.MailItem

Public Function fncSendeMail(strSubject As String, strMsg As String, strTo As String, _
Optional ctlAttach As ListBox, Optional strCCTo As String = vbNullString, _
Optional yesDraft As Boolean = True, Optional SendTime As Date)
On Error GoTo errHandler
Dim strMsgID As String
Dim strMsgConf As String
Dim i As Long

Set OlApp = CreateObject("Outlook.Application")
Set eMsg = OlApp.CreateItem(olMailItem)

eMsg.Subject = strSubject
eMsg.To = strTo
eMsg.CC = strCCTo

If ctlAttach.ListCount > 0 And Len(strMsg) > 0 Then
'The vbCr additions to the strMsg ensure that the
'attachments follow the message on a visibly new line
eMsg.Body = strMsg & vbCr & vbCr
Else
eMsg.Body = strMsg
End If
For i = 0 To ctlAttach.ListCount - 1
' Embed a file into the new message
'Constant Value Behavior
'--------------------------------------------------------
'olByValue 1 Creates embedded attachment
'olByReference 4 Creates shortcut to attachment
'olEmbeddedItem 5 Creates shortcut to attachment
'olOLE 6 Creates shortcut to attachment
eMsg.Attachments.Add (ctlAttach.List(i)), olByValue
Next
eMsg.Save
strMsgID = eMsg.EntryID

If Not yesDraft Then 'If false, message will appear in Draft, otherwise in Outbox
eMsg.Send
strMsgConf = "Message has been posted into Outlook's Outbox." & vbCr & vbCr _
& "Delivery of internet eMail will commence when" & vbCr _
& "next online."
Else
strMsgConf = "Message has been posted into Outlook's draft folder." & vbCr & vbCr _
& "Delivery of draft mail will commence only when items" & vbCr _
& "are specifically sent from within Outlook."
End If

Set eMsg = Nothing
Set OlApp = Nothing
Set olAttachment = Nothing

MsgBox strMsgConf, vbOKOnly + vbInformation, "Message Transferred"

Exit Function

errHandler:
MsgBox Err.Number & vbCr & Err.Description

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top