steven.darby
Registered User.
- Local time
- Today, 15:18
- Joined
- Dec 21, 2009
- Messages
- 10
Open Outlook email app. and attach a file using VBA OFFICE07
HI, hoping someone has something relatively simple, or can direct me to the right place, I want to open Outlook email application on click and attach a document (I have the full file path and file extension)
To date I've only ever used Docmd.sendobject <access report>, can I use this to send a document. My db isnt using actual attachments, I am just storing filepaths in a table. I guess then, next question is do I need to save the original document to the database first as some sort of temporary attachment perhaps?
I'm not interested in actually sending the email, or closing the app after, just to open if not already, add to: & subject: and attach a doc.
- - - - - - -
I've tracked down some code from the forums but I get error "user type not defined " on first line ... Dim Myoutlook as outlook.application
not a very good start I know, I am however using access 07 in case this is anything to do with, any help much appreciated
>> NOW FIXED ! -- In VBA tools, references menu I didnt have Microsoft Outlook 12.0 Object Library set, just checked the box and now all working fine! Code insert...
HI, hoping someone has something relatively simple, or can direct me to the right place, I want to open Outlook email application on click and attach a document (I have the full file path and file extension)
To date I've only ever used Docmd.sendobject <access report>, can I use this to send a document. My db isnt using actual attachments, I am just storing filepaths in a table. I guess then, next question is do I need to save the original document to the database first as some sort of temporary attachment perhaps?
I'm not interested in actually sending the email, or closing the app after, just to open if not already, add to: & subject: and attach a doc.
- - - - - - -
I've tracked down some code from the forums but I get error "user type not defined " on first line ... Dim Myoutlook as outlook.application
not a very good start I know, I am however using access 07 in case this is anything to do with, any help much appreciated
>> NOW FIXED ! -- In VBA tools, references menu I didnt have Microsoft Outlook 12.0 Object Library set, just checked the box and now all working fine! Code insert...
Code:
Public Function Email_now()
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim objOutlook As Object
Dim Attach As String
'Check if outlook if open
Set objOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0
If objOutlook Is Nothing Then
' Enter code to open outlook...
'still working on this !!
End If
' Now, we open Outlook for our own device..
Set MyOutlook = New Outlook.Application
' This creates the e-mail
Set MyMail = MyOutlook.CreateItem(olMailItem)
' This addresses it
MyMail.To = "test" '**put in reference to form
'MyMail.CC = MailList("Copy To")
'This gives it a subject
MyMail.Subject = "test" '**put in reference for subject
'This gives it the body
MyMail.Body = "test"
'If you want to send an attachment
'uncomment the following line
Attach = "C:\users\home_steven\test.txt" '** add file path to attach doc
MyMail.Attachments.Add Attach
'This sends it!
'MyMail.Send
'To Display instead of Send, Uncomment the next line
'And comment the "MyMail.Send" line above this.
MyMail.Display
'Cleanup after ourselves
Set MyMail = Nothing
'Uncomment the next line if you want Outlook to shut down when its done.
'Otherwise, it will stay running.
'MyOutlook.Quit
Set MyOutlook = Nothing
End function
Last edited: