Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50057

VBA Code - PDF Output as opposed to Excel

$
0
0
Hi

any help would be greatly appreciated....

i have the following code which does the following

1) cycles through a list of numbers which in turn trigger a vlookup
2) makes an excel copy of the document and gives it the name of the number
3) then emails to specific TO/CC with the excel document attached

I have adapted the code to attempt to save/send a PDF instead of the excel doc and it falls over on the following line


.Attachments.Add Directory & FileTag

anybody got any ideas how to fix?

if you could tell me the physical code i need that would be brilliant

many thanks

Jason





Sub SendTargetSheets()

'Variables that need defining (Need Updating)

Dim Cell As Range
Dim strbody As String
Dim Directory As String
Dim wrkbk As Workbook
Dim CalcFileName As String
Dim EmailSubject As String
Dim FileTag As String
Dim AddressTo As String
Dim AddressCC As String
Dim OutApp As Object
Dim OutMail As Object

'Variable Definitions (Need Updating)

Directory = "Z:\Scorecard\FY14\BSC Target Sheets\Distributed\P1\"
CalcFileName = "Branch Target Sheet V1 - April 2013 (P1).pdf"
EmailSubject = "FY14 P1 Branch Scorecard Target Sheet"

'Enter Email Content Here (Need Updating)

strbody = "Dear Store Manager" & vbNewLine & vbNewLine
strbody = strbody & "Attached is your Scorecard Target Sheet for April 2013 (P1)." & vbNewLine & vbNewLine
strbody = strbody & "Please direct all questions and queries to your Area Manager." & vbNewLine & vbNewLine
strbody = strbody & "Kind Regards" & vbNewLine & vbNewLine
strbody = strbody & "Finance" & vbNewLine & vbNewLine & vbNewLine

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)

'Select Next Branch Number in Range

For Each Cell In Range("MacroStores").Cells.SpecialCells(xlCellTypeConstants)
Sheets("Target Sheet").Range("G5") = Cell.Value
FileTag = Range("NewFileName").Value
AddressTo = Range("AddressTo").Value
AddressCC = Range("AddressCC").Value
Sheets("Target Sheet").Copy
Set wrkbk = ActiveWorkbook
With wrkbk.Sheets("Target Sheet")
.Cells.Copy
.Cells.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
.Range("A1").Select
End With
wrkbk.ExportAsFixedFormat xlTypePDF, Directory & FileTag, xlQualityStandard

'Email new file to distriubtion list
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = AddressTo
.CC = AddressCC
.Subject = EmailSubject
.Attachments.Add Directory & FileTag
.Body = strbody
.Send
End With
Set OutMail = Nothing
wrkbk.Close

Next Cell

Viewing all articles
Browse latest Browse all 50057

Trending Articles