View Single Post
  #6   Report Post  
Ken Wright
 
Posts: n/a
Default

LOL - it looks a lot scarier than it really is - try this for a step by step
guide using Ron's code.

Hit ALT+F11 and this will open the VBE (Visual Basic Editor)
Top left you will hopefully see an explorer style pane. Within this pane
you need to search for your workbook's name, and when you find it you may
need to click on the + to expand it. Within that you should see the
following:-

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
ThisWorkbook

If you have named your sheets then those names will appear in the brackets
above as opposed to
what you see at the moment in my note.

Right click on the where it says VBAProject(Your_Filename) and choose
'Insert Module' and it will now look like this

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
ThisWorkbook
Modules
Module1

Double click the Module1 bit and then paste in Ron's code starting at the
Sub Mail_workbook_Outlook()
bit and finishing at the End Sub bit.


Sub Mail_workbook_Outlook()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim strto As String

For Each cell In ThisWorkbook.Sheets("Sheet1") _
.Columns("C").Cells.SpecialCells(xlCellTypeConstan ts)
If cell.Value Like "*@*" Then
strto = strto & cell.Value & ";"
End If
Next
strto = Left(strto, Len(strto) - 1)

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = strto
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add ("C:\test.doc")
.Send 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

The ranges in Ron's code will likely need changing to suit your data, eg in
the line that says

For Each cell In ThisWorkbook.Sheets("Sheet1")

you will need to either change the Sheet1 to the name of your sheet or vice
versa. Also, Ron's code assumes the addresses are in Col C on that sheet,
hence the line that says

.Columns("C").Cells.SpecialCells(xlCellTypeConstan ts)

so if it's not Col C then just change the C to whatever it actually is in
your sheet.

Then hit File / Close and return to Microsoft Excel and save the file. Now
just do Tools / Macro / Macros / Mail_workbook


You can stop at that point, but if for any reason you then want to get rid
of the macro, then simply do the following:-

Hit ALT+F11 and this will open the VBE (Visual Basic Editor)
Top left you will hopefully see an explorer style pane. Within this pane
you need to search for
your workbook's name, and when you find it you may need to click on the + to
expand it. Within
that you should see the following:-

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
etc..........................
ThisWorkbook
Modules
Module1

Right click on the Module1 and select remove. When prompted with a question
re exporting, just hit no. Then hit File / Close and return to Microsoft
Excel and save the
file.


--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 97/00/02/03

----------------------------------------------------------------------------
It's easier to beg forgiveness than ask permission :-)
----------------------------------------------------------------------------
<snip