trying to add 2 cells to a save as pdf file

Doghole

New Member
Joined
Jul 2, 2019
Messages
3
Hi,

his s the code I am using but where it says =range("C5") I want to add another cell like H1 but I must be blind and can not find it on here. I have tried multiple ways but just cant figure it out. sorry

Sub saveaspdf()
ChDir "C:\Users\he138642\Desktop\Test INVOICE"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("C5").Value _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True

End Sub
 

Some videos you may like

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,701
Office Version
365
Platform
Windows
Not tested, but it should work:
Code:
Sub saveaspdf()
ChDir "C:\Users\he138642\Desktop\Test INVOICE"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("C5").Value & Range("H1").Value _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True

End Sub
 

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,701
Office Version
365
Platform
Windows
... or if you want a space character between the two strings...
Code:
Sub saveaspdf()ChDir "C:\Users\he138642\Desktop\Test INVOICE"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("C5").Value & " " & Range("H1").Value _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True

End Sub
 

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,701
Office Version
365
Platform
Windows
Sorry - that should have been:
Code:
Sub saveaspdf()
ChDir "C:\Users\he138642\Desktop\Test INVOICE"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("C5").Value & " " & Range("H1").Value _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True

End Sub
 

Doghole

New Member
Joined
Jul 2, 2019
Messages
3
Thankyou so much that worked perfectly
 

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,701
Office Version
365
Platform
Windows
You're welcome. Glad it worked for you, and thanks for the feedback.

By the way - I failed to notice that this was your first post here, so Welcome to Mr. Excel! It's a superb resource - probably the most comprehensive out there - with some VERY switched-on folk here to help... of which I'm not one. I'm on the "B" team!
Enjoy!
 

Doghole

New Member
Joined
Jul 2, 2019
Messages
3
yeah I have only just started and finding it fun to play with. I have this code which im playing with now but would you know how I can attach the email. thinking im missing something like labelling my saveas filename so I can use that name in the .attachments. Add filename. but no I a hurry as 'm getting to it when I can to play with it. It does everything I want it t do just wont attach .PDF


Sub EMAIL()
ChDir "C:\Users\he138642\Desktop\Test INVOICE"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("C5").Value & " " & Range("H1").Value _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
On Error Resume Next
Dim OutApp As Variant
Dim OutMail As Variant
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = Range("E7")
.Subject = "Invoice From Peter Fleer Electrical"
.Body = "Attached is the invoice from peter fleer electrical services" & Chr(13) & Chr(13) & "Kind Regards," & Chr(13) & "Peter Fleer." & Chr(13) & "0498 711 663."
On Error Resume Next
.attachments.Add Filename
.Save
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing

End Sub
 

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,701
Office Version
365
Platform
Windows
Something like this should work:
Code:
On Error Resume Next
.attachments.Add "C:\Users\he138642\Desktop\Test INVOICE" & Range("C5").Value & " " & Range("H1").Value
.Save
.Display
End With
On Error GoTo 0
 

Watch MrExcel Video

Forum statistics

Threads
1,102,889
Messages
5,489,547
Members
407,698
Latest member
Lotte_4

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top