I can send my user form by e-mail, but I want to attach a Word file prior to the message being sent. The Word file is a requirement for me to process the form.
How do I use VBA code to create a pop-up for the user to browse for the Word doc and attach it along with the worksheet in the same email ?
Sub SendWorkSheet()
Dim xFile As String
Dim xFormat As Long
Dim Wb As Workbook
Dim Wb2 As Workbook
Dim FilePath As String
Dim fileName As String
Dim OutlookApp As Object
Dim OutlookMail As Object
On Error Resume Next
Application.ScreenUpdating = False
Set Wb = Application.ActiveWorkbook
ActiveSheet.Copy
Set Wb2 = Application.ActiveWorkbook
Select Case Wb.FileFormat
Case xlOpenXMLWorkbook:
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
Case xlOpenXMLWorkbookMacroEnabled:
If Wb2.HasVBProject Then
xFile = ".xlsm"
xFormat = xlOpenXMLWorkbookMacroEnabled
Else
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
End If
Case Excel8:
xFile = ".xls"
xFormat = Excel8
Case xlExcel12:
xFile = ".xlsb"
xFormat = xlExcel12
End Select
FilePath = Environ$("temp") & "\"
fileName = Wb.Name & Format(Now, "dd-mmm-yy h-mm-ss")
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Wb2.SaveAs FilePath & fileName & xFile, FileFormat:=xFormat
With OutlookMail
.To = "...@..."
.CC = ""
.BCC = ""
.Subject = "NEW eForm Authorization"
.Body = "New Manual eForm Authorization. Please do not process. This is just a test"
.Attachments.Add Wb2.FullName
.Send
End With
Wb2.Close
Kill FilePath & fileName & xFile
Set OutlookMail = Nothing
Set OutlookApp = Nothing
Application.ScreenUpdating = True
'//POP UP MESSAGE CONFIRMING EMAIL WAS SENT
MsgBox ("Your eForm Authorization has now been sent to: ...@.... You may close this file as a copy now appears in your sent items folder.")
End Sub
How do I use VBA code to create a pop-up for the user to browse for the Word doc and attach it along with the worksheet in the same email ?
Sub SendWorkSheet()
Dim xFile As String
Dim xFormat As Long
Dim Wb As Workbook
Dim Wb2 As Workbook
Dim FilePath As String
Dim fileName As String
Dim OutlookApp As Object
Dim OutlookMail As Object
On Error Resume Next
Application.ScreenUpdating = False
Set Wb = Application.ActiveWorkbook
ActiveSheet.Copy
Set Wb2 = Application.ActiveWorkbook
Select Case Wb.FileFormat
Case xlOpenXMLWorkbook:
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
Case xlOpenXMLWorkbookMacroEnabled:
If Wb2.HasVBProject Then
xFile = ".xlsm"
xFormat = xlOpenXMLWorkbookMacroEnabled
Else
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
End If
Case Excel8:
xFile = ".xls"
xFormat = Excel8
Case xlExcel12:
xFile = ".xlsb"
xFormat = xlExcel12
End Select
FilePath = Environ$("temp") & "\"
fileName = Wb.Name & Format(Now, "dd-mmm-yy h-mm-ss")
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Wb2.SaveAs FilePath & fileName & xFile, FileFormat:=xFormat
With OutlookMail
.To = "...@..."
.CC = ""
.BCC = ""
.Subject = "NEW eForm Authorization"
.Body = "New Manual eForm Authorization. Please do not process. This is just a test"
.Attachments.Add Wb2.FullName
.Send
End With
Wb2.Close
Kill FilePath & fileName & xFile
Set OutlookMail = Nothing
Set OutlookApp = Nothing
Application.ScreenUpdating = True
'//POP UP MESSAGE CONFIRMING EMAIL WAS SENT
MsgBox ("Your eForm Authorization has now been sent to: ...@.... You may close this file as a copy now appears in your sent items folder.")
End Sub