VBA Print to PDF not printing entire page.

STML_JW

New Member
Joined
Nov 12, 2014
Messages
29
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

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!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
when you look at in print preview is it visible ?
 
Upvote 0
Yes, whenever I print it out, it prints perfectly fine. If I print as a pdf manually it prints fine.
 
Upvote 0

Forum statistics

Threads
1,216,117
Messages
6,128,935
Members
449,480
Latest member
yesitisasport

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