i am a beginner at VBA and need help with this code. I placed on my sheet command button and connected it with macro (the code is down there) "PrintSelectionToPDF" and it goes smoothly through code until i press button cancel (if changed my mind and don't want to save selected range as PDF) in inputbox it sends me error message -> run-time error '424' Oject required [enter image description here][1]
-> this part of code->
Set ThisRng = Application.InputBox("Select a range", "Get Range", Type:=8)
Thank you in advance if you can find me a solution.
`Sub PrintSelectionToPDF()
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`