A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

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 » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Microsoft Word Help
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

How do I insert a To: email address in visual basic?



 
 
Thread Tools Display Modes
  #1  
Old July 21st 08, 03:37 PM posted to microsoft.public.word.docmanagement
Ray7071
external usenet poster
 
Posts: 2
Default How do I insert a To: email address in visual basic?

I have Form with a Button which when clicked causes the (completed) form to
be attached to an email. Thr Email is generated ok with the Form attached. I
want to pre-set the To: email address to my own to save the user typing it
in. It would also be nice if I could pre-set a few words in the body of the
email but this is not too important.

I can use a 'Mailto' hyperlink to get an email to myself but this doen not
attach the document.

Any ideas would be much appreciated.

Tahnks, Ray.
Ads
  #2  
Old July 21st 08, 03:57 PM posted to microsoft.public.word.docmanagement
Graham Mayor
external usenet poster
 
Posts: 19,312
Default How do I insert a To: email address in visual basic?

The problem with this is that you may not know what e-mail software your
users are using. If you are certain they are all using Outlook, then you
could use something like:

Sub SendDocumentAsAttachment()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved
ActiveDocument.Save 'so save it
End If
'see if Outlook is running and if so turn your attention there
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err 0 Then 'Outlook isn't running
'So fire it up
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Open a new e-mail message
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = 'send to this address
.Subject = "New subject" 'This is the message subject
.Body = "See attached document" ' This is the message body text
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue
.Send
'**********************************
'If you want to view the message before it goes
'change the line above from .Send to .Display
'Otherwise the message is sent straight to the Outbox
'and if you have Outlook set to send mail immediately,
'it will simply be Sent
'with no obvious sign that Outlook has operated.
'Apart from the copy in the Outlook Sent folder
'**********************************
End With
If bStarted Then 'If the macro started Outlook, stop it again.
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

http://www.gmayor.com/installing_macro.htm
--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




Ray7071 wrote:
I have Form with a Button which when clicked causes the (completed)
form to be attached to an email. Thr Email is generated ok with the
Form attached. I want to pre-set the To: email address to my own to
save the user typing it in. It would also be nice if I could pre-set
a few words in the body of the email but this is not too important.

I can use a 'Mailto' hyperlink to get an email to myself but this
doen not attach the document.

Any ideas would be much appreciated.

Tahnks, Ray.




 




Thread Tools
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
Word Visual Basic ksawb Microsoft Word Help 1 November 5th 07 10:33 AM
Visual Basic error 438 Rose Jenkins Microsoft Word Help 1 September 6th 07 06:26 AM
Visual Basic text box Marty Mailmerge 1 September 7th 06 09:57 AM
Visual Basic Macro MISSA New Users 3 August 24th 06 02:30 PM
Visual Basic and VBA Forum Throne Software Mailmerge 0 July 9th 05 04:23 AM


All times are GMT +1. The time now is 11:38 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2004-2019 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.