• Need VBA code to attach ACTIVE PDF to Lotus Notes e-mail

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Need VBA code to attach ACTIVE PDF to Lotus Notes e-mail

    Author
    Topic
    #484523

    Hello,

    I have been using the VBA code below to attach the ACTIVE Excel file to the Lotus Notes email. I have recently created another macro that does a “file save as” function to save the ACTIVE Excel file as a PDF file. The macro below will not attach the ACTIVE PDF file… it gives me an error and stops at:

    ’Retrieve the path and filename of the active workbook.
    stAttachment = ActiveWorkbook.FullName

    I’m guessing I need to change the wording from “ActiveWorkbook.FullName” to something else because the active PDF is what I’d like to attach.

    Any help is very much appreciated!

    Thanks!
    Lana

    Sub SendEmail()

    Dim noSession As Object, noDatabase As Object, noDocument As Object
    Dim obAttachment As Object, EmbedObject As Object

    Dim stSubject As Variant, stAttachment As String

    Dim vaRecipient As Variant, vaMsg As Variant

    Const EMBED_ATTACHMENT As Long = 1454

    ‘Retrieve the path and filename of the active workbook.
    stAttachment = ActiveWorkbook.FullName

    ‘Initiate the Lotus Notes COM’s Objects.
    Set noSession = CreateObject(“Notes.NotesSession”)
    Set noDatabase = noSession.GETDATABASE(“”, “”)

    ‘If Lotus Notes is not open then open the mail-part of it.
    If noDatabase.IsOpen = False Then noDatabase.OPENMAIL

    ‘Create the e-mail and the attachment.
    Set noDocument = noDatabase.CreateDocument
    Set obAttachment = noDocument.CreateRichTextItem(“stAttachment”)

    Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, “”, stAttachment)

    vaRecipient = Range(“A3”)

    Viewing 1 reply thread
    Author
    Replies
    • #1342389

      You will need to pass in the path where the PDF is saved.

      What code do you have that creates the PDF? What filename is given to the file in that piece of the code? You need to define that PDF file path as a variable and pass it to the SendEmail sub you showed us.

    • #1343010

      Assuming the PDF has already been created and has the same name as the workbook (except for the extension), you should be able to use:
      stAttachment = Split(ActiveWorkbook.FullName, “.”)(0) & “.pdf”
      Note that this won’t work if there are periods in the filename (not a good practice, anyway)

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

    Viewing 1 reply thread
    Reply To: Need VBA code to attach ACTIVE PDF to Lotus Notes e-mail

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: