wilkisa
Well-known Member
- Joined
- Apr 7, 2002
- Messages
- 660
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
I need help tweaking a macro to create a PDF file out of a set range and then emailing it to a group of people.
I know that I have a conflict in my code between the Application.Dialogs(XLDialogSendMail).show statement and in the ActiveWorkbook.SendMail line of the code. I realize these aren't compatible statements but I don't know which one to fix.
I want the code to automatically put the distribution list name in the email and send it; my user doesn't want to have to put in the listname or user names manually.
My code is as follows:
<html>Private Sub cmdConvertEmail_Click()
' The following code will convert Sheet3 to a PDF file
Dim FileName As String
FileName = SHEET3(Range("B1:G44"), "", True, True)
'Unprotect the worksheet
ActiveSheet.Unprotect
'Convert to PDF
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
"C:\Users\BREADS BAGELS BUNS.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
'Application.Dialogs(xlDialogSendMail).Show
'Hide the email button button before sending
cmdConvertEmail.Visible = False
'Send the email to group
ActiveWorkbook.SendMail Recipients:="myemail@myaddress.com", Subject:="New business"
'Unhide the email button
cmdEmail.Visible = True
'Reprotect the worksheet
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub</html>
Can someone help me with this?
I know that I have a conflict in my code between the Application.Dialogs(XLDialogSendMail).show statement and in the ActiveWorkbook.SendMail line of the code. I realize these aren't compatible statements but I don't know which one to fix.
I want the code to automatically put the distribution list name in the email and send it; my user doesn't want to have to put in the listname or user names manually.
My code is as follows:
<html>Private Sub cmdConvertEmail_Click()
' The following code will convert Sheet3 to a PDF file
Dim FileName As String
FileName = SHEET3(Range("B1:G44"), "", True, True)
'Unprotect the worksheet
ActiveSheet.Unprotect
'Convert to PDF
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
"C:\Users\BREADS BAGELS BUNS.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
'Application.Dialogs(xlDialogSendMail).Show
'Hide the email button button before sending
cmdConvertEmail.Visible = False
'Send the email to group
ActiveWorkbook.SendMail Recipients:="myemail@myaddress.com", Subject:="New business"
'Unhide the email button
cmdEmail.Visible = True
'Reprotect the worksheet
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub</html>
Can someone help me with this?