trying to add 2 cells to a save as pdf file

Doghole

New Member
Joined
Jul 2, 2019
Messages
5
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
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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
 
Upvote 0
... 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
 
Upvote 0
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
 
Upvote 0
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!
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,491
Messages
6,113,963
Members
448,536
Latest member
CantExcel123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top