Saving file in PDF & attaching it to email

Falcon

New member
Joined
Mar 25, 2013
Messages
9
Reaction score
0
Points
0
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
 
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:
[B]Dim olApp As Outlook.Application
Dim olMail As MailItem
[/B][B]Dim PDFPath As String[/B]
[B]Dim Email As String[/B]
[B]Dim File As String[/B]
 
 
[B]PDFPath = ThisWorkbook.Path & Application.PathSeparator[/B]
[B]Email = sht.Range("B1")[/B]
[B]File = sht.Range("F1") & ".pdf"[/B]
   
[B]            Set olApp = New Outlook.Application[/B]
[B]            Set olMail = olApp.CreateItem(olMailItem)[/B]
 
[B]            With olMail[/B]
[B]                .To = Email[/B]
[B]                .CC = ""[/B]
[B]                .Subject = "subject"[/B]
[B]                .Body = "body tekst"[/B]
[B]                .Attachments.Add PDFPath & File[/B]
[B]                .Display[/B]
[B]                .Send[/B]
[B]            End With[/B]
    
[B]            Set olMail = Nothing[/B]
[B]            Set olApp = Nothing[/B]
 
Back
Top