Option Base 1
Sub Mail_Sheets()
'Working in 97-2010
Dim Sourcewb As Workbook, Destwb As Workbook
Dim sh As Worksheet, I As Long, strto As String
Dim TheActiveWindow As Window, TempWindow As Window
Dim shtArray(), X As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
Set Sourcewb = ActiveWorkbook
On Error Resume Next
'Verzend de tabbladen in kolom E naar iedere spelers die in het bereik ("B1:B150") staat.
For Each cell In ThisWorkbook.Sheets("e-mailadressen") _
.Range("B1:B150").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" Then
strto = strto & cell.Value & ";"
End If
Next cell
On Error GoTo 0
If Len(strto) > 0 Then strto = Left(strto, Len(strto) - 1)
'Make a list of the worksheets to copy and make a copy
sq = Sheets("e-mailadressen").Range("E2:E" & Sheets("e-mailadressen").Range("E20").End(xlUp).Row)
For X = 1 To UBound(sq)
Sheets(sq(X, 1)).Copy Before:=Sheets(1)
With ActiveSheet
.Unprotect
.Cells.Copy
.Cells.PasteSpecial Paste:=xlPasteValues
'.Protect
End With
Application.CutCopyMode = False
Next
Set Sourcewb = ActiveWorkbook
'Copy the sheets to a new workbook
'We add a temporary Window to avoid the Copy problem
'if there is a List or Table in one of the sheets and
'if the sheets are grouped
With Sourcewb
Set TheActiveWindow = ActiveWindow
Set TempWindow = .NewWindow
For Each ws In .Worksheets
If Right(ws.Name, 3) = "(2)" Then
intA = intA + 1
ReDim Preserve shtArray(intA)
shtArray(intA) = ws.Name
End If
Next ws
.Sheets(shtArray).Copy
End With
'Close temporary Window
TempWindow.Close
Set Destwb = ActiveWorkbook
'Save the new workbook/Mail it/Delete it
With Destwb
.SaveAs Environ$("temp") & "\" & "'t Sluissse VOETBALSPEL " & Format(Now, "dd-mmm-yy") & ".xlsx", _
FileFormat:=51
On Error Resume Next
Dim N As Long
With Application
'if necessary change this message
'scroll down to the message field
For N = 1 To 5
.SendKeys "{TAB}", Wait:=True
Next
.Dialogs(xlDialogSendMail).Show strto, _
"'t Sluisse VOETBALSPEL " & Format(Now, "yyyy")
End With
On Error GoTo 0
.Close SaveChanges:=False
End With
'Delete the file you have send
Kill Environ$("temp") & "\" & "'t Sluissse VOETBALSPEL " & Format(Now, "dd-mmm-yy") & ".xlsx"
Sheets(shtArray).Delete
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
End With
End Sub