+ Reply to Thread
Results 1 to 9 of 9

VBA save document as PDF in folder and attached to an outlook email

  1. #1
    Registered User
    Join Date
    12-16-2020
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    28

    Post VBA save document as PDF in folder and attached to an outlook email

    Hi,

    I'm very new to VBA coding but attempting to save a worksheet as a PDF file named after a relative cell within the sheet (cell F4). i also then want the PDF to attach to an outlook email with a basic message.

    Ive got the pdf saving to the location so far but struggling with the rest. Also i was hoping for an error message to occur when the PDF document name attempts to saves as a duplication.

    any help would be much appreciated.

    Code i have so far:


    Please Login or Register  to view this content.

    Thanks
    Danny
    Last edited by davesexcel; 12-18-2020 at 06:04 AM.

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: VBA save document as PDF in folder and attached to an outlook email

    your desired code is all over the internet. please start here:

    https://www.google.com/search?q=exce...+outlook+email

    and here:

    https://www.google.com/search?q=vba+...add+attachment

  3. #3
    Registered User
    Join Date
    12-16-2020
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    28

    Re: VBA save document as PDF in folder and attached to an outlook email

    Hi Adam,

    Thanks for the tips, your links have certainly helped me understand better the concepts of VBA. However i still need a lot more educating, which is my intention over xmas and the new year. Im still struggling with this code but believe im really close to finalizing. i have the following code working apart from saving the pdf name as the range in cell "f3" (currently saving as the workbook name). If you could correct my error it would be much appreciated.

    Please Login or Register  to view this content.
    Thanks Danny
    Last edited by davesexcel; 12-18-2020 at 06:03 AM.

  4. #4
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA save document as PDF in folder and attached to an outlook email

    Try to change Filename:=xfolder to Filename:=activesheet.[F3].value

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA save document as PDF in folder and attached to an outlook email

    Danny1986, welcome to the forum.

    Please use Code Tags when posting code according to Forum Rule #2.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Registered User
    Join Date
    12-16-2020
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    28

    Re: VBA save document as PDF in folder and attached to an outlook email

    Hi

    Thanks for everyone comments but where im inexperienced and new to VBA im still struggling. i attempted them all and couldn't get to work still.

    this was my latest attempt:

    Please Login or Register  to view this content.
    Initially it displays a runtime error 91 for the r = Range("f3") section, which i believe should have "set" at the start (please correct me if im wrong), however it then fails to save in the location and furthermore come up with a runtime error for the .Attachments.Add xFolder Part.

    your soonest help would be much appreciated before my head exploded lol

    thanks
    Danny

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA save document as PDF in folder and attached to an outlook email

    Try this way.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    12-16-2020
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    28

    Re: VBA save document as PDF in folder and attached to an outlook email

    That's amazing, it works perfect now. Thanks Bakerman2

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA save document as PDF in folder and attached to an outlook email

    You're welcome and thanks for rep+.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Create MS Outlook Email from Excel and Save to Draft Folder
    By jski21 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-07-2020, 05:55 AM
  2. Check if email is unread in outlook then save attachment to folder
    By sonyat810 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-23-2018, 03:10 PM
  3. [SOLVED] How to get outlook email attachment using excel vba and save it in a specified folder
    By jrtraylor in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-25-2016, 08:34 PM
  4. [SOLVED] Macro to attached sheet to outlook email
    By Rajesh shishodia in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-31-2015, 10:46 AM
  5. Save an Outlook attachment and move the email to a folder based and sender
    By db16886 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2014, 09:49 PM
  6. Replies: 0
    Last Post: 09-12-2013, 07:43 AM
  7. Replies: 0
    Last Post: 06-26-2013, 01:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1