I am trying to print a range of one worksheet ( Sheet: "HR001", Range "A1:L50") and it is not printing the whole sheet. This is basically a form that contains electronic signatures of folks for training they go through.
I have a good portion of the page that is fed data through a userform, or pulls some from previous sheets. All cells from either of these methods are not included in the pdf when it is printed. Also, there is no formatting included either (cell borders, etc). It also seems that all bold text is not included either.
If i .print instead of export to pdf then all data and formatting is correct. Where have I gone wrong? Here is the code used to actually export
and how I am pulling my filename
Any help understanding where I went wrong, and possible help fixing it, would be greatly appreciated.
Thank you!
I have a good portion of the page that is fed data through a userform, or pulls some from previous sheets. All cells from either of these methods are not included in the pdf when it is printed. Also, there is no formatting included either (cell borders, etc). It also seems that all bold text is not included either.
If i .print instead of export to pdf then all data and formatting is correct. Where have I gone wrong? Here is the code used to actually export
Code:
Sheets("HR001").Activate
Dim filename As String: filename = GetFileName(Range("H53"))
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, filename:=filename, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
and how I am pulling my filename
Code:
Function GetFileName(rngNamedCell As Range) As String
Dim strSaveDirectory As String: strSaveDirectory = ""
Dim strFileName As String: strFileName = ""
Dim strTestPath As String: strTestPath = ""
Dim strFileBaseName As String: strFileBaseName = ""
Dim strFilePath As String: strFilePath = ""
Dim intFileCounterIndex As Integer: intFileCounterIndex = 1
' Get the users desktop directory.
strSaveDirectory = Environ("USERPROFILE") & "\Desktop\"
Debug.Print "Saving to: " & strSaveDirectory
' Base file name
strFileBaseName = Trim(rngNamedCell.Value)
Debug.Print "File Name will contain: " & strFileBaseName
' Loop until we find a free file number
Do
If intFileCounterIndex > 1 Then
' Build test path base on current counter exists.
strTestPath = strSaveDirectory & strFileBaseName & Trim(Str(intFileCounterIndex)) & ".pdf"
Else
' Build test path base just on base name to see if it exists.
strTestPath = strSaveDirectory & strFileBaseName & ".pdf"
End If
If (Dir(strTestPath) = "") Then
' This file path does not currently exist. Use that.
strFileName = strTestPath
Else
' Increase the counter as we have not found a free file yet.
intFileCounterIndex = intFileCounterIndex + 1
End If
Loop Until strFileName <> ""
' Found useable filename
Debug.Print "Free file name: " & strFileName
GetFileName = strFileName
End Function
Any help understanding where I went wrong, and possible help fixing it, would be greatly appreciated.
Thank you!