Results 1 to 7 of 7

Thread: help with email code please

  1. #1

    help with email code please



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hi Everyone

    i have this code 1 inside Code 2,

    Code:
    
    
    
    '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
    Attached Files Attached Files
    Last edited by Pecoflyer; 2016-05-20 at 07:45 AM.

  2. #2
    im really sorry admin for some reason i cant edit this post to put code in brackets

  3. #3
    Code 2
    Code:
    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
    Code:
    Application.Dialogs(xlDialogSendMail).Show

  4. #4
    Administrator Pecoflyer's Avatar
    Join Date
    Oct 2011
    Location
    Brussels Belgium
    Posts
    1,655
    Articles
    0
    Excel Version
    2010 on Xubuntu
    Quote Originally Posted by flyinghigher2014 View Post
    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
    Thank you Ken for this secure forum.

  5. #5

    code

    Quote Originally Posted by Pecoflyer View Post
    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
    Attached Files Attached Files

  6. #6
    Administrator Pecoflyer's Avatar
    Join Date
    Oct 2011
    Location
    Brussels Belgium
    Posts
    1,655
    Articles
    0
    Excel Version
    2010 on Xubuntu
    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.
    Thank you Ken for this secure forum.

  7. #7
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,319
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    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.
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •