Email and Excel / Question for Ron DeBruin

C

carl

Hi Ron. I just had a chance to try a suggested fix. I
could not get the macro to run. Would greatly appreciate
if you could take a look. To refresh. I am trying to email
a spreadsheet based on the filtered email address in
column k. The modification I am trying to construct is to
email to the filtered address in k and an ajoining address
in col l. Thank you in advance.

Here's the patch:

Dim str As Variant

For Each cell In Columns("K").Cells.SpecialCells
(xlCellTypeFormulas)
If cell.EntireRow.Hidden = False And cell.Value
Like "*@*" Then
str = Array(cell.Value, cell.Offset(0,
1).Value, cell.Offset(0, 2).Value)
Exit For
End If
Next cell

Here's the original code:

Sub Mail_Selection2()
Dim source As Range
Dim dest As Workbook
Dim strdate As String
Dim cell As Range
Dim str As String

Set source = Nothing
On Error Resume Next
Set source = Selection.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If source Is Nothing Then
MsgBox "The source is not a range or the sheet is
protect, please correct and try again.", vbOKOnly
Exit Sub
End If

If ActiveWindow.SelectedSheets.Count > 1 Or _
Selection.Cells.Count = 1 Or _
Selection.Areas.Count > 1 Then
MsgBox "An Error occurred :" & vbNewLine &
vbNewLine & _
"You have more than one sheet selected." &
vbNewLine & _
"You only selected one cell." & vbNewLine &
_
"You selected more than one area." &
vbNewLine & vbNewLine & _
"Please correct and try again.", vbOKOnly
Exit Sub
End If

Application.ScreenUpdating = False

For Each cell In Columns("K").Cells.SpecialCells
(xlCellTypeFormulas)
If cell.EntireRow.Hidden = False And cell.Value
Like "*@*" Then
str = cell.Value
Exit For
End If
Next cell

Set dest = Workbooks.Add(xlWBATWorksheet)
source.Copy
With dest.Sheets(1)
.Cells(1).PasteSpecial paste:=8
' Paste:=8 will copy the column width in Excel
2000 and higher
' If you use Excel 97 use the other example
.Cells(1).PasteSpecial xlPasteValues, , False,
False
.Cells(1).PasteSpecial xlPasteFormats, , False,
False
.Cells(1).Select
Application.CutCopyMode = False
End With

strdate = Format(Now, "dd-mm-yy h-mm-ss")

With dest
.SaveAs "Selection of " & ThisWorkbook.Name _
& " " & strdate & ".xls"
.SendMail str, _
"This is the Subject line"
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub
 
R

Ron de Bruin

Hi carl

My suggestion was to split up the addresses in different columns
The example I send you will send to the address in column K,L and M

Str = Array(cell.Value, cell.Offset(0, 1).Value, cell.Offset(0, 2).Value)

Send me(private) your workbook and I will look at it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top