Thread: Emailing Files
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Don M. Don M. is offline
external usenet poster
 
Posts: 51
Default Emailing Files

I used Ron's links to do this very same thing and it works like a charm! I'm
sure there is a way to use values in a cell to determine who the message gets
sent to.

Dim SendEmail As String
SendEmail = Worksheets("Run Report").Cells(2, 22)
If SendEmail = 1 Then GoTo Line2012:


Dim TradeShowCopies As Integer
TradeShowCopies = Worksheets("TradeShow Copies").Cells(10, 2)
If TradeShowCopies = 0 Then GoTo Line1012:

Dim rng As Range
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds

..Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

..Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"mail.mail.int"

..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With


Set rng = Nothing
On Error Resume Next

Set rng = Sheets("TradeShow
Copies").Range("a1:j8").SpecialCells(xlCellTypeVis ible)

On Error GoTo 0

If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.EnableEvents = False
.ScreenUpdating = False
End With

With iMsg
Set .Configuration = iConf
.To = "username"
.From = "username"
.Subject = "Subject here"
.HTMLBody = RangetoHTML(rng)
.Send
End With

With Application
.EnableEvents = True
.ScreenUpdating = True
End With

Line1012:

Don