I am trying to add a button to a form which will pick up an email address, launch outlook, place the address in "Sendto" field and then let me manually type a letter.
I have always used the code below but this only works for sending a message then closing outlook having sent an automated message. I need it to keep outlook open.
I am really a self taught novice at this and only found the code by chance and sure it will be easy for someone with knowledge.
Hope you can assist.
Regards
jacc14
Expand|Select|Wrap|Line Numbers
- Private Sub Command9_Click()
- Dim bStarted As Boolean
- Dim oOutlookApp As Outlook.Application
- Dim oItem As Outlook.MailItem
- On Error Resume Next
- 'Get Outlook if it's running
- Set oOutlookApp = GetObject(, "Outlook.Application")
- If Err <> 0 Then
- 'Outlook wasn't running, start it from code
- Set oOutlookApp = CreateObject("Outlook.Application")
- bStarted = True
- End If
- 'Create a new mailitem
- Set oItem = oOutlookApp.CreateItem(olMailItem)
- With oItem
- 'Set the recipient for the new email
- .To = "jacc14@testing.co.uk"
- .Send
- End With
- If bStarted Then
- ' 'If we started Outlook from code, then close it
- oOutlookApp.Quit
- End If
- 'Clean up
- Set oItem = Nothing
- Set oOutlookApp = Nothing
- End Sub