Trouble with Excel Selection to PDF

McNab

New Member
Joined
Jun 26, 2021
Messages
3
Office Version
  1. 2010
Platform
  1. Windows
  2. MacOS
Hi lovely people

I usued this forum years ago but have always love it.

Basically I am trying to print a certain selection of cells from Excel to a PDF
(a) I want the macro to define a static range
(b) I want it to the name the file
(c) I want the hyperlinks in the file to work when I send it out

I have tried a bunch of macros but am on Mac and using Fusion for my Excel work. Each time I get an error. It feels like a printeer problem albeit being a total novice I don't understand what a printer has to do with writing to PDF from Excel.

Here are some of the ones I have tried. Basically I am starting a SPA company and need to send a schedule to our therapists. I have worked our the simple stuff but can't get the **** to PDF to print.

I hope you are well and someone can help. It would be much appreciated.

Thank you.

VBA I have tried but doesn't seem to work. I can send individual error messages if needed.


Sub PrintSelectionToPDF()
'SUBROUTINE: PrintSelectionToPDF
'DEVELOPER: Ryan Wells
'DESCRIPTION: Print your currently selected range to a PDF

Dim ThisRng As Range
Dim strfile As String
Dim myfile As Variant

If Selection.Count = 1 Then
Set ThisRng = Application.InputBox("Select a range", "Get Range", Type:=8)
Else
Set ThisRng = Selection
End If
'Prompt for save location
strfile = "Selection" & "_" _
& Format(Now(), "yyyymmdd_hhmmss") _
& ".pdf"
strfile = ThisWorkbook.Path & "\" & strfile

myfile = Application.GetSaveAsFilename _
(InitialFileName:=strfile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and File Name to Save as PDF")

If myfile <> "False" Then 'save as PDF
ThisRng.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
myfile, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
Else
MsgBox "No File Selected. PDF will not be saved", vbOKOnly, "No File Selected"
End If

End Sub

Sub ExportToPDF()

With Sheets("Jenny").Range("c4:J18")
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="C:\downloads\Jenny_Today.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End With

End Sub

Sub ExcelWordPaste()

Dim objWord As Object
Dim objDoc As Object

Set objWord = CreateObject("Word.Application")
objWord.Visible = True

Range("c4:j18").Copy

Set objDoc = objWord.documents.Add
With objDoc.Range
.PasteExcelTable False, False, False
.Tables(1).AutoFitBehavior 2 'wdAutoFitWindow
.InsertAfter vbCr
End With
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Welcome!

VBA I have tried but doesn't seem to work. I can send individual error messages if needed.
Yep. Please include these, including on which line they occur. It's hard to help without knowing what the error is.
It feels like a printeer problem albeit being a total novice I don't understand what a printer has to do with writing to PDF from Excel.
I don't know this for sure, but my guess is it might be using printer drivers to do the actual export - i.e. if you File → Print → Microsoft Print to PDF or Microsoft XPS Document Writer, you might end up with the same result. Someone else might better know, however.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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