Sub SaveAsPDF()
Dim strBasePath As Variant, PdfFileName As Variant, strPtName As Range, strPtID As Range, strPlanName As Range, strMach As String
Set strPtName = Worksheets("Dose Measurement").Range("d8")
Set strPtID = Worksheets("Dose Measurement").Range("d10")
Set strPlanName = Worksheets("Dose Measurement").Range("k8")
strMach = Worksheets("Dose Measurement").Range("k10")
PdfFileName = strPtName & " " & strPtID
If IsEmpty(strPtName) Or IsEmpty(strPtID) Or IsEmpty(strPlanName) Or strMach = "Select here" Or strMach = "" Then
MsgBox "Please enter all Patient Demographics" & vbCrLf & vbCrLf & "Click Ok to continue", Buttons:=vbInformation, Title:="FOR YOUR INFORMATION"
strPtName.Select
Exit Sub
End If
With ActiveDocument
On Error GoTo Errhandler
StrPath = GetFolder & ""
Application.PrintCommunication = False 'this temporarily turns off the communication to the printer to avoid Run-time error
'‘1004’: Unable to set the FitToPagesTall property of the PageSetup class
If PdfFileName <> False Then
With ActiveSheet.PageSetup
.Orientation = x1Portrait
.PrintArea = "$b$2:$n$91"
.FitToPagesWide = 1
.FitToPagesTall = 0
End With
Application.PrintCommunication = True
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=StrPath & PdfFileName & " " & "Point Dose", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
MsgBox "PDF file: " & vbCrLf & vbCrLf & PdfFileName & " " & "Point Dose" & (".pdf") & vbCrLf & vbCrLf & "has been created.", Buttons:=vbInformation, Title:="FOR YOUR INFORMATION"
End If
exitHandler:
Exit Sub
Errhandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End With
End Sub
Function GetFolder() As String
Dim oFolder As Object, strBasePath As Variant
strBasePath = "[URL="file://\\hneahs.nswhealth.net\shares\Tamworth"]\\hneahs.nswhealth.net\shares\Tamworth[/URL] NWCC\Medical Physics\Treatment Planning\01 Plan Checking\02 Dynamic Treatments\01 Treated Patients"
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0, strBasePath)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function