Hi,
Tried searching but couldn’t find anything that helped.
I have inherited a macro that sends the active sheet as an attachment to a recipient (based on a pull down) via email.
I want to include additional attachments if a checkbox is checked (Linked to cell CA29).
The code below works, as in when you select the send button it sends the sheet to email as an attachment but the issue I’m having is,
The selection window pops up for you to select a file to attach whether or not you have the check box checked or not.
This is the section I added for additional attacents.
If Range("CA29") = True Then
.Attachments.Add (wbFullName)
Else
End If
Can someone help please.
Private Sub Manager_Email_Click()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim strbody As String
Dim wbFullName As Variant
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sourcewb = ActiveWorkbook
'Copy the ActiveSheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook
wbFullName = Application.GetOpenFilename("All Files (*.*), *.*")
'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2013
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End With
'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With Destwb
Call Delete_My_Named_Ranges
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.To = Manager_Name.Value
.CC = ""
.BCC = ""
.Subject = "Approval Required - Training Request Form"
.Body = "Your approval is needed on this Training Request Form," & vbCrLf & _
"Please select approved or rejected on the form" & vbCrLf & _
"and submit the form to the Training Co-Ordinator" & vbCrLf & _
"If Rejected, please add comments and reply to Initiator of form"
.Attachments.Add Destwb.FullName
If Range("CA29") = True Then
.Attachments.Add (wbFullName)
Else
End If
'.Send 'or use .Display
.Display
End With
On Error GoTo 0
.Close savechanges:=False
End With
MsgBox "This Form has been submited to the Your Selected Manager."
'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr
ActiveWorkbook.Close False
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Bookmarks