Save active worksheet as new workbook in PDF format

toughie

New Member
Joined
Oct 10, 2018
Messages
43
Hi All,

The code below returns an error -Run-time error '1004': Document not saved.

anyone know why?

(Error on line .ExportAsFixedFormat...)

VBA Code:
Private Sub CommandButton1_Click()
Range("B10").Activate
If IsError(ActiveCell) Then
UserForm1.Hide
UserForm3.Show vbModeless
Else

PdfFile = "C:\Users\tougand\Desktop\PHOSPHATE MACRO\" & Range("B7") & Range("B8")
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, fileName:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With

ThisWorkbook.Close SaveChanges:=True
End If
Exit Sub
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Does that folder exist?


Exactly what data do you have in those cells?

You can activate the macro recorder, save the active sheet as pdf, go back to macros and stop the macro recorder. Paste here the generated code.

Hi Dante,

I ran a record macro and that doesnt let me save as PDF either i get an error saying - Document Not Saved

"C:\Users\tougand\Desktop\PHOSPHATE MACRO\" - Also the folder does exist.

Range("B7") & Range("B8") containt text and numbers for example B7 = 1072858262 and B8 = H0A12314

Just for info - I am trying to export one worksheet only from the workbook and save it as PDF
 
Upvote 0
What version of office and excel do you have?
Maybe you need to install some plugin to be able to save documents as pdf.
 
Upvote 0
Sorry I don't have 2016 to test.
Maybe someone else can guide us to download the add-in or maybe you need other software to save as a pdf.
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

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