willow1985
Well-known Member
- Joined
- Jul 24, 2019
- Messages
- 921
- Office Version
- 365
- Platform
- Windows
Hello,
I have the below code but I am looking to add something to it. Once the Macro has run but before the message box stating update complete, what I would like it to do is:
go to Sheet "CAPA Log", copy rows A1:P1, paste in an e-mail, then copy the last row with data (A:P) and paste that info in the e-mail as well (headers and last row of data), then automatically e-mail it to a select group of people (person1@email.com, person2@email.com etc) with the subject line: New Capa Added to the Log.
Then finish with the message box, update complete and e-mail sent.
How would I go about modifying the below code to achieve this? I put a large blank area in the code showing where I would like to add it.
Sub Update_CAPA()
'
' Update_CAPA Macro
'
Dim Msg As String, Ans As Variant
Msg = "Would you like to update the CAPA Log with this Data?"
Ans = MsgBox(Msg, vbYesNo)
Select Case Ans
Case vbYes
Sheets("New CAPA").Select
Range("A2:O2").Select
Selection.Copy
Sheets("CAPA Log").Select
Range("CAPA_Log").Cells(1, 1).End(xlDown).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("CAPA_Log").Cells(1, 1).End(xlDown).Offset(1).Select
Sheets("New CAPA").Select
Range("B2:O2").Select
Selection.ClearContents
Range("B2").Select
Sheets("Table1").Visible = True
Sheets("Table2").Visible = True
Sheets("Table2").Visible = True
Sheets("Table1").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
Sheets("Table2").Select
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
Sheets("Table3").Select
ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
Sheets("Graphs").Select
ActiveSheet.ChartObjects("ADChart").Activate
ActiveChart.PivotLayout.PivotTable.PivotCache.Refresh
ActiveSheet.ChartObjects("StatusChart").Activate
ActiveChart.PivotLayout.PivotTable.PivotCache.Refresh
ActiveSheet.ChartObjects("TypeChart").Activate
ActiveChart.PivotLayout.PivotTable.PivotCache.Refresh
Sheets("Table1").Visible = False
Sheets("Table2").Visible = False
Sheets("Table2").Visible = False
Sheets("New CAPA").Select
Range("B2").Select
Sheets("New CAPA").Select
Range("B2").Select
MsgBox "Update Complete and Email Sent"
Case vbNo
GoTo Quit:
End Select
Quit:
I have the below code but I am looking to add something to it. Once the Macro has run but before the message box stating update complete, what I would like it to do is:
go to Sheet "CAPA Log", copy rows A1:P1, paste in an e-mail, then copy the last row with data (A:P) and paste that info in the e-mail as well (headers and last row of data), then automatically e-mail it to a select group of people (person1@email.com, person2@email.com etc) with the subject line: New Capa Added to the Log.
Then finish with the message box, update complete and e-mail sent.
How would I go about modifying the below code to achieve this? I put a large blank area in the code showing where I would like to add it.
Sub Update_CAPA()
'
' Update_CAPA Macro
'
Dim Msg As String, Ans As Variant
Msg = "Would you like to update the CAPA Log with this Data?"
Ans = MsgBox(Msg, vbYesNo)
Select Case Ans
Case vbYes
Sheets("New CAPA").Select
Range("A2:O2").Select
Selection.Copy
Sheets("CAPA Log").Select
Range("CAPA_Log").Cells(1, 1).End(xlDown).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("CAPA_Log").Cells(1, 1).End(xlDown).Offset(1).Select
Sheets("New CAPA").Select
Range("B2:O2").Select
Selection.ClearContents
Range("B2").Select
Sheets("Table1").Visible = True
Sheets("Table2").Visible = True
Sheets("Table2").Visible = True
Sheets("Table1").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
Sheets("Table2").Select
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
Sheets("Table3").Select
ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
Sheets("Graphs").Select
ActiveSheet.ChartObjects("ADChart").Activate
ActiveChart.PivotLayout.PivotTable.PivotCache.Refresh
ActiveSheet.ChartObjects("StatusChart").Activate
ActiveChart.PivotLayout.PivotTable.PivotCache.Refresh
ActiveSheet.ChartObjects("TypeChart").Activate
ActiveChart.PivotLayout.PivotTable.PivotCache.Refresh
Sheets("Table1").Visible = False
Sheets("Table2").Visible = False
Sheets("Table2").Visible = False
Sheets("New CAPA").Select
Range("B2").Select
Sheets("New CAPA").Select
Range("B2").Select
MsgBox "Update Complete and Email Sent"
Case vbNo
GoTo Quit:
End Select
Quit: