• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Export userform as a pdf

Rodrigues

Member
Hi All
I've been using below code without any problems on 32bit, however doesn't work in 64bit.

Code:
      ' Export UserForm as PDF (image)
    Dim pdfName As String
    Dim newWS As Worksheet

    keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
    keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
    '
    DoEvents 'Otherwise, all of screen would be pasted as if PrtScn rather than Alt+PrtScn was used for the copy.
     '
        ''Amended 20161007 1640
         Set newWb = Workbooks.Add
    newWb.Sheets(1).PasteSpecial Format:="Bitmap", Link:=False, DisplayAsIcon:=False
    With newWb.Sheets(1).PageSetup
        .Orientation = xlLandscape
        .PrintArea = "$A$1:$R$60"
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
        .PaperSize = xlPaperA4
    End With
                ''
    pdfName = "C:\Test\PDF" & "\" & Me.Name & "-" & Format(Now, "yyyy-mmm-dd hmm") & "-" & Me.Label35.Caption & "-" & Me.Label1.Caption & "-" & Me.Label49.Caption & "-" & Me.Label50.Caption & ".pdf"
                ''
    '
    newWb.Sheets(1).ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:=pdfName, Quality:=xlQualityStandard, _
        IncludeDocProperties:=False, IgnorePrintAreas:=False, _
        OpenAfterPublish:=False
    Application.DisplayAlerts = False
    newWb.Close False
    Application.DisplayAlerts = True

Have added on a module below. but get the folowing error: Compile error Sub or Function not defined and highlight keydb_event...
Code:
#If VBA7 Then
    Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal ms As LongPtr)
#Else
    Private Declare Sub Sleep Lib "kernel32" (ByVal ms as Long)
#End If

Any help will be much appreciated
Regards
Rodrigues
 
Back
Top