Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default adding email addresses to auto email


Hi All,

I have a spreadsheet that I use to automatically pick teams for my
football club, one button picks random teams the other opens a new
Outlook message and pastes the teams into it ready to send.

I use the following to paste into the email:

Private Sub CommandButton2_Click()

'Dimension variables
Dim oOutlookApp As Object, oOutlookMessage As Object
Dim oFSObj As Object, oFSTextStream As Object
Dim rngeSend As Range, strHTMLBody As String, strTempFilePath As
String

'Select the range to be sent
On Error Resume Next
Set rngeSend = ActiveSheet.Range("f22:g32")
If rngeSend Is Nothing Then Exit Sub
'User pressed Cancel
On Error GoTo 0


'Get the temp folder path
Set oFSObj = CreateObject("Scripting.FilesystemObject")
strTempFilePath = oFSObj.GetSpecialFolder(2)
strTempFilePath = strTempFilePath & "\XLRange.htm"


'Create the HTML file
ActiveWorkbook.PublishObjects.Add(4, strTempFilePath, _
rngeSend.Parent.Name,
rngeSend.Address, 0, "", "").Publish True

'Create an instance of Outlook (or use existing instance if it
already exists
Set oOutlookApp = CreateObject("Outlook.Application")

'Create a mail item
Set oOutlookMessage = oOutlookApp.CreateItem(0)

'Open the HTML file using the FilesystemObject into a TextStream
object
Set oFSTextStream = oFSObj.OpenTextFile(strTempFilePath, 1)

'Now set the HTMLBody property of the message to the text contained
in the TextStream object
strHTMLBody = oFSTextStream.ReadAll

strHTMLBody = Replace(strHTMLBody, "align=center", "align=left", ,
, vbTextCompare)

oOutlookMessage.HTMLBody = strHTMLBody

oOutlookMessage.Display

End Sub

What I would like to do now is add the email addresses to the message
and also if possible a subject header including the date of the next
game.

The email addresses are contained in a range on the master sheet but
I'm unsure if it will be possible to do this - anyone got any ideas ?

Jayce


--
Bigjayce
------------------------------------------------------------------------
Bigjayce's Profile: http://www.excelforum.com/member.php...fo&userid=2487
View this thread: http://www.excelforum.com/showthread...hreadid=508889

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default adding email addresses to auto email

See Ron de Bruin's site for examples of how to do this:

http://www.rondebruin.nl/sendmail.htm

--
Regards,
Tom Ogilvy


"Bigjayce" wrote in
message ...

Hi All,

I have a spreadsheet that I use to automatically pick teams for my
football club, one button picks random teams the other opens a new
Outlook message and pastes the teams into it ready to send.

I use the following to paste into the email:

Private Sub CommandButton2_Click()

'Dimension variables
Dim oOutlookApp As Object, oOutlookMessage As Object
Dim oFSObj As Object, oFSTextStream As Object
Dim rngeSend As Range, strHTMLBody As String, strTempFilePath As
String

'Select the range to be sent
On Error Resume Next
Set rngeSend = ActiveSheet.Range("f22:g32")
If rngeSend Is Nothing Then Exit Sub
'User pressed Cancel
On Error GoTo 0


'Get the temp folder path
Set oFSObj = CreateObject("Scripting.FilesystemObject")
strTempFilePath = oFSObj.GetSpecialFolder(2)
strTempFilePath = strTempFilePath & "\XLRange.htm"


'Create the HTML file
ActiveWorkbook.PublishObjects.Add(4, strTempFilePath, _
rngeSend.Parent.Name,
rngeSend.Address, 0, "", "").Publish True

'Create an instance of Outlook (or use existing instance if it
already exists
Set oOutlookApp = CreateObject("Outlook.Application")

'Create a mail item
Set oOutlookMessage = oOutlookApp.CreateItem(0)

'Open the HTML file using the FilesystemObject into a TextStream
object
Set oFSTextStream = oFSObj.OpenTextFile(strTempFilePath, 1)

'Now set the HTMLBody property of the message to the text contained
in the TextStream object
strHTMLBody = oFSTextStream.ReadAll

strHTMLBody = Replace(strHTMLBody, "align=center", "align=left", ,
, vbTextCompare)

oOutlookMessage.HTMLBody = strHTMLBody

oOutlookMessage.Display

End Sub

What I would like to do now is add the email addresses to the message
and also if possible a subject header including the date of the next
game.

The email addresses are contained in a range on the master sheet but
I'm unsure if it will be possible to do this - anyone got any ideas ?

Jayce


--
Bigjayce
------------------------------------------------------------------------
Bigjayce's Profile:

http://www.excelforum.com/member.php...fo&userid=2487
View this thread: http://www.excelforum.com/showthread...hreadid=508889



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Macro how to create email link for the email addresses in aRange or Selection Satish[_2_] Excel Worksheet Functions 8 December 28th 09 03:30 PM
Adding email addresses from Excel into Outlook Scooter Excel Discussion (Misc queries) 1 December 15th 09 04:47 PM
can I copy a column of email addresses, paste into email address? Lizizfree New Users to Excel 4 July 20th 06 10:03 PM
Email addresses in Excel need to format for mass email Boomer Excel Worksheet Functions 1 June 9th 06 01:46 PM
Transfer Email addresses from spreadsheet to email address book Beana Excel Discussion (Misc queries) 2 May 30th 06 06:07 PM


All times are GMT +1. The time now is 07:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"