JonnyBT123
New Member
- Joined
- Jul 23, 2018
- Messages
- 14
Hi all,
Ive spent some time creating (and also modifying from RonDe Bruin) an emailer, where basically my control page (named SYSINI) has namesin column A, email addresses in column B and a Yes or No in column D.
If D2 says Yes:
Copy page called Emailer,rename to the email address, copy/paste full new page as values, send as email attachmentto the email address in B2, delete the page with the email address name, and repeatfor each row.
If not, move on to D3 etc andloop until the row in column D is blank.
Ive got the part where it does the copy/paste/rename of thepage etc, but when adding the emailer around it, so it sends the email, I justget the code looping and skips everything between where Ive marked **SKIPSHERE** until the part marked **UNTIL HERE**
Any idea where Im going wrong please? There are no errorcodes, just a continuous loop with nothing happening.
Ive spent some time creating (and also modifying from RonDe Bruin) an emailer, where basically my control page (named SYSINI) has namesin column A, email addresses in column B and a Yes or No in column D.
If D2 says Yes:
Copy page called Emailer,rename to the email address, copy/paste full new page as values, send as email attachmentto the email address in B2, delete the page with the email address name, and repeatfor each row.
If not, move on to D3 etc andloop until the row in column D is blank.
Ive got the part where it does the copy/paste/rename of thepage etc, but when adding the emailer around it, so it sends the email, I justget the code looping and skips everything between where Ive marked **SKIPSHERE** until the part marked **UNTIL HERE**
Any idea where Im going wrong please? There are no errorcodes, just a continuous loop with nothing happening.
Code:
Sub SendEmails()
'
' Sendemails Macro
'
Dim OutApp As Object
Dim OutMail As Object
Dim ShtName As String
Dim SavName As String
Dim cell As Range
Dim ws As Worksheet
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
Set ws = Worksheets("SYSINI")
On Error GoTo cleanup
For Each cell In ws.Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "D").Value) = "yes" Then
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''***SKIPS EVERYTHING BELOW HERE....**
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Range(cell.Row, "B").Select
Selection.Copy
ws.Range("M1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ShtName = ws.Range("M1").Value
SavName = ShtName & "_" & ws.Range("H1")
Sheets("Emailer").Select
Range("F13").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(LEFT(SYSINI!R1C13,LEN(SYSINI!R1C13)-7)&ROW(RC[-1])-12,NewPivot!C3:C9,COLUMN(R[-11]C),FALSE),"""")"
Range("F14").Select
Sheets("Emailer").Copy Before:=Sheets(7)
Sheets("Emailer (2)").Select
Sheets("Emailer (2)").Name = ShtName
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets(ShtName).Select
Sheets(Array("Report1", "Processes", "NewPivot", "Emailer", "Completed" _
, "SYSINI")).Select
ActiveWindow.SelectedSheets.Visible = False
ActiveWorkbook.SaveAs FileName:= _
"C:/SharepointServerAddressHere" & ShtName & SavName & ".xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Sheets(ShtName).Select
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Reminder"
.Body = "Dear " & Sheets("SYSINI").Range("L1").Value _
& vbNewLine & vbNewLine & _
"Please see attached for you to action."
.Attachments.Add ("MySharePointServerAddressAgain/" & ShtName & SavName & ".xlsm")
.Display 'Or use Send
End With
On Error GoTo 0
Set OutMail = Nothing
End If
'''''''''''''''''''''''''''''''''
'''**UNTIL HERE**
'''''''''''''''''''''''''''''''''''
Sheets("Report1").Visible = True
Sheets("NewPivot").Visible = True
Sheets("Processes").Visible = True
Sheets("Emailer").Visible = True
Sheets("Completed").Visible = True
Sheets("SYSINI").Visible = True
Application.DisplayAlerts = False
Sheets(ShtName).Delete
Sheets("SYSINI").Select
Application.DisplayAlerts = True
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub