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
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