Results 1 to 3 of 3

Thread: Saving file in PDF & attaching it to email

  1. #1

    Thumbs up Saving file in PDF & attaching it to email



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

    Hi,

    I have used following code to save file in PDF to my desktop. ( this is achieved it by assigning macro to a 'Form' button)
    But I now want to save it at other location than desktop such as ...... X:\SP\CA\Mar in PDF format with file name as per data in row 9D:9G ( basically 9D:9G will have date , name etc).

    I also want now this to be attached as PDF document to a specified email address.

    Can this be done? Please help.

    Current code is as follows:

    Code:
    Private Sub CommandButton1_Click()
    Sub exportaspdf()
     Dim desktoploc As String
     Dim filename As String
     Dim mypath As String
    
    
    desktoploc = CreateObject("WScript.Shell").SpecialFolders("Desktop")
    filename = ThisWorkbook.Name
    mypath = desktoploc & "\" & filename
    
    
       ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:=mypath, _
           Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
          :=False, OpenAfterPublish:=True
    
    
    
    
    End Sub

  2. #2
    Hi all,
    can any one help please
    regards

  3. #3
    I have something similar. Email address is in cell B1, and filename in F1. You need to check outlook app in Tools>references in the vba-window.

    Code:
    Dim olApp As Outlook.Application
    Dim olMail As MailItem
    Dim PDFPath As String
    Dim Email As String
    Dim File As String
     
     
    PDFPath = ThisWorkbook.Path & Application.PathSeparator
    Email = sht.Range("B1")
    File = sht.Range("F1") & ".pdf"
       
                Set olApp = New Outlook.Application
                Set olMail = olApp.CreateItem(olMailItem)
     
                With olMail
                    .To = Email
                    .CC = ""
                    .Subject = "subject"
                    .Body = "body tekst"
                    .Attachments.Add PDFPath & File
                    .Display
                    .Send
                End With
        
                Set olMail = Nothing
                Set olApp = Nothing

Posting Permissions

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