Code for exprt as Pdf

Chris1973

Board Regular
Joined
Apr 17, 2020
Messages
115
Office Version
  1. 2016
Platform
  1. Windows
Gooday everyone.

Still me with my problem of exporting a excel sheet to pdf format.

I have tried numerous codes ( which strangely enough work on their own)

My problem is i need to save a excel workbook(xlsm enabled) to xlsx and pdf format .

I am currently using this code for the sake of saving to xlsx, and it works 100%

PLEASE NOTE THIS CODE WORK 100% NO PROBLEM HERE

Private Sub CommandButton1_Click()

Dim Path As String

Dim Filename1 As String

Path = "C:\Users\chrish\Documents\1.Wurth Master\3.Quotes and Brochures\Excel\"
Filename1 = Range("D8").Text
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=Path & Filename1 & ".xlsx", FileFormat:=xlOpenXMLWorkbook
Application.DisplayAlerts = True
ActiveWorkbook.Close


End Sub

I need a code to save above mentioned code and then to EXPORT PDF

pdf must be exported (saved) to

cell range : D4 AND D8 must be saved
Path: C:\Users\chrish\Documents\1.Wurth Master\3.Quotes and Brochures\Pdf

so in short
xlsx must be saved in
range:D8
PATH:"C:\Users\chrish\Documents\1.Wurth Master\3.Quotes and Brochures\Excel\"

and pdf must be saved to

cell range : D4 AND D8 must be saved
Path: C:\Users\chrish\Documents\1.Wurth Master\3.Quotes and Brochures\Pdf


Anyone that can help.

I had tremendous help over the weekend, unfortunately for one or other reason does nothing want to work
 
But if you manually save the file as pdf, do you get the file?
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Yes then it is there

Is it possible to change the way the export to pdf/xps command with reference cell d4:d8

I can use the command button i created then just to save to excel.

I am truly at my wits end, have no idea what am i doing wrong, the problem here is that everything i do is from videos i saw, so i have no knowledge of macros/language/code
 
Upvote 0
Is it possible to change the way the export to pdf/xps command with reference cell d4:d8

VBA Code:
  Filename2 = range("D4").Value & " " & range("D8").Text
  'SAVE PDF
  Application.DisplayAlerts = False
  ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=Path2 & Filename2, Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

This code is for that, to generate the pdf taking as name the data in cells d4 and d8.
Maybe it's a problem in your excel version that doesn't allow you to save with macro.
 
Upvote 0
i can save pdf with Macros, if i don't have the xlsx code.

But the moment that i try for both of them to work together, that is when it does not want to save. I can save then either xlsx or pdf, bit not both at same time
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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