PDA

View Full Version : help with email code please



flyinghigher2014
2016-05-19, 07:45 PM
Hi Everyone

i have this code 1 inside Code 2,





'Print the invoice to PDFSub PrintPDFInvoice() 'turn off screenupdating Application.ScreenUpdating = False If Range("N13") = "" Then MsgBox "Please Enter The Invoice Date" Exit Sub ElseIf Range("N16") = "" Then MsgBox "Please Enter The Start Date For Your Contract Hire" Exit Sub ElseIf Range("N17") = "" Then MsgBox "Please Enter The End Date For Your Contract Hire" Exit Sub ElseIf Range("G12") = "" Then MsgBox "Please add the company" Exit Sub End If 'open dialog and set file type Opendialog = Application.GetSaveAsFilename(Sheet2.Range("N15") & Sheet2.Range("N14"), filefilter:="PDF Files (*.pdf), *.pdf", _ Title:="Save Me Baby!!") 'if no value is added for file name If Opendialog = False Then MsgBox "I take it you forgot to do something!!" Exit Sub End If 'set the named range for the PDF Set MyRange = Sheet2.Range("G6:N54") Sheet2.PageSetup.PrintArea = "G6:N54" 'create the PDF On Error Resume Next MyRange.ExportAsFixedFormat _ Type:=xlTypePDF, _ Filename:=Sheet2.Range("N15") & Sheet2.Range("N14"), _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ OpenAfterPublish:=True On Error GoTo 0 'clear the page breaks ActiveSheet.DisplayPageBreaks = False Application.ScreenUpdating = False Application.Dialogs(xlDialogSendMail).Show End Sub
when i use code 2 it save the file as required by combining two cells "our0112". but what happens is when i add code 1 it simply opens outlook and adds the original file, and not the saved pdf. could someone please help with this.

also id like the the email to be sent to an email address that i have to the client that is select on the invoice (vlookup, i think). so if i select KN Group then the email that i have for that client would be used. eg sales@kn-group.ie and if i change the client on the invoice to GE Lighting then then email for that client would be used.

im sorry if it all sounds complicated.

ive attached my file as i thought that would help

thank you in advance
Paul

flyinghigher2014
2016-05-19, 09:07 PM
im really sorry admin for some reason i cant edit this post to put code in brackets

flyinghigher2014
2016-05-19, 09:09 PM
Code 2
Code:


'Print the invoice to PDFSub PrintPDFInvoice()'turn off screenupdatingApplication.ScreenUpdating = FalseIf Range("N13") = "" ThenMsgBox "Please Enter The Invoice Date"Exit SubElseIf Range("N16") = "" ThenMsgBox "Please Enter The Start Date For Your Contract Hire"Exit SubElseIf Range("N17") = "" ThenMsgBox "Please Enter The End Date For Your Contract Hire"Exit SubElseIf Range("G12") = "" ThenMsgBox "Please add the company"Exit SubEnd If'open dialog and set file typeOpendialog = Application.GetSaveAsFilename(Sheet2.Range("N15") & Sheet2.Range("N14"), filefilter:="PDF Files (*.pdf), *.pdf", _Title:="Save Me Baby!!")'if no value is added for file nameIf Opendialog = False ThenMsgBox "I take it you forgot to do something!!"Exit SubEnd If'set the named range for the PDFSet MyRange = Sheet2.Range("G6:N54")Sheet2.PageSetup.PrintArea = "G6:N54"'create the PDFOn Error Resume NextMyRange.ExportAsFixedFormat _Type:=xlTypePDF, _Filename:=Sheet2.Range("N15") & Sheet2.Range("N14"), _Quality:=xlQualityStandard, _IncludeDocProperties:=True, _IgnorePrintAreas:=False, _OpenAfterPublish:=TrueOn Error GoTo 0'clear the page breaksActiveSheet.DisplayPageBreaks = FalseApplication.ScreenUpdating = FalseApplication.Dialogs(xlDialogSendMail).Show End Sub


Application.Dialogs(xlDialogSendMail).Show

Pecoflyer
2016-05-20, 07:40 AM
im really sorry admin for some reason i cant edit this post to put code in brackets

The code in post #1 is unusable as is. Post or send me a text file containing it under usual form, and I will edit your post to make it usable so you can be helped

flyinghigher2014
2016-05-20, 07:45 AM
The code in post #1 is unusable as is. Post or send me a text file containing it under usual form, and I will edit your post to make it usable so you can be helped

attached is the text file

Pecoflyer
2016-05-20, 07:48 AM
Thanks
There seems to be a problem with the code tags. I'll send a message to admin to see what's going on. Sorry.

Meanwhile I will close this thread and move your post in VBA programming to Outlook. The format seems OK there.

If you need to contact me you can also PM.

Ken Puls
2016-06-01, 04:07 PM
Hey there,

Yes, every now and then, the code tags eat all the hard returns. I don't know why, and I haven't figured out what the trigger point is.

I'm not saying that this is the best answer but when this happens to me I copy and paste the original code to Notepad, then copy it into the post. It's irritating to be sure.

The only way to fix it now is to go through and re-insert the hard returns. Pretty long piece of code though. :(