Saving Range Selection as PDF on Mac - excel

I have the following code to try and export a specific selection as a one-page PDF. I was able to grant access but I can't seem to be able to export the selection as a PDF. I get a 1004 error. Any advice?
Sub PrintTest()
ChDir "/Users/Mr_Madoff/Desktop/"
Sheets("Sheet1").Range("A1:F53").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
"/Users/Mr_Madoff/Desktop/Book1.pdf", Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
End Sub

Related

Excel VBA: Save active worksheet as PDF

I've been using some code to save an active worksheet to PDF, using the current date/time as the filename, and saving into a SharePoint folder.
Sub Save()
Dim strFilename As String
strFilename = Format(Now(), "yyyy-mm-dd hhmm")
Sheets("Weather Warning Action Sheet").Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"https://xxx.sharepoint.com/sites/xxx/xxx/Paperwork and Admin/WX Warnings/2020/" & strFilename & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
End Sub
This code has been working fine for a while, but has suddenly come up with the "Run-time error '1004': Document not saved" error message.
Debugging shows this as the error:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"https://xxx.sharepoint.com/sites/xxx/xxx/Paperwork and Admin/WX Warnings/2020/" & strFilename & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Any assistance would be greatly appreciate.
Many thanks,
James

Runtime error 1004 for code that worked fine

I have the following code in a spreadsheet that's been used for months in the office:
Private Sub CommandButton2_Click()
With Sheets("Summary").Range("B2:H83")
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="F:\Export.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End With
End Sub
Today, when I try to execute I get a Runtime error 1004.
We did a recent Office 365 update, could that be the culprit?

How to export from Excel to PDF to a determined location?

I have this code to export to PDF, but it goes to the documents folder. I'd like to export it to a different location. How do I do that?
This is the code:
Private Sub CommandButton1_Click()
Range("a1:k44").Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ru & "REMITO " & Range("C7") & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
Export excel as PDF to a specific path, you can use the code below. You will need to adjust it to your needs, this is the base.
Private Sub CommandButton1_Click()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="path_here+filename.pdf"
End sub
Example:
Filename:="C:\Documents\newfolder2\archive.pdf"

PDF print to file path VBA

I have the below code I have researched and got to work in one of my workbooks. The idea of the code is to automatically print a sheet to PDF and save down in a directory of my choosing naming it the contents of a specific cell.
All works fine until I try to copy into a new workbook (I designed in a test workbook as not to corrupt the original) then I get a
run time error 1004
and the ThisWorkbook.Sheets(Array("sheet 2")).Select is highlighted when I debug. Am I missing something simple? as the code works in the original workbook but not in if I paste into a new module in a new workbook? Sorry i'm quite new to this!
sub PrintPDFRT()
Sheets("test").Activate
ActiveSheet.UsedRange.Select
Sheets("malbru1").Activate
ActiveSheet.UsedRange.Select
Sheets("sheet 2").Activate
Range("A1:j137").Select
ThisWorkbook.Sheets(Array("sheet 2")).Select
Selection.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="FIle path\" & Range("L7").Value, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub
Try it like this: (without Array)
sub PrintPDFRT()
WorkSheets("test").Activate
ActiveSheet.UsedRange.Select
WorkSheets("malbru1").Activate
ActiveSheet.UsedRange.Select
WorkSheets("sheet 2").Activate
Range("A1:j137").Select
ThisWorkbook.WorkSheets("sheet 2").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="FIle path\" & Range("L7").Value, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub

Save Excel range as pdf

I'd like to 'save as' a specific sheet or specific range to pdf.
I tried implementing a range into my code.
Here is what I've been working with:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"c:\Book1.pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
you have the code, just use a range instead of activesheet
e.g. Sheets("Sheet1").Range("B2:H28").ExportAsFixedFormat ...

Resources