Now when i run the form i get a pop up box asking what macro to run. I changed Lib "user32" to Lib "user64" but that didnt seem to help. UserForm1.PrintForm 'change UserForm1 to suit. OldPrinter = Left$(Application.ActivePrinter, InStrRev(Application.ActivePrinter, "on ") - 2)ĬhangePrinter "PDFCreator" '"HP LaserJet 8000 Series PCL" Public Sub ChangePrinter(NewPrinter As String) Private Declare Function SendNotifyMessage Lib "user32" Alias "SendNotifyMessageA" ( _ ByVal hwnd As Long, _ ByVal msg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function SetDefaultPrinter Lib "winspool.drv" _ Alias "SetDefaultPrinterA" (ByVal pszPrinter As String) As Long Private Const WM_WININICHANGE As Long = &H1A Private Const HWND_BROADCAST As Long = &HFFFF& IgnorePrintAreas:=False, OpenAfterPublish:=False Quality:=xlQualityStandard, IncludeDocProperties:=True, _ ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdf, _ Note 2: The line OpenAfterPublish: True tells VBA to open the PDF as soon as it is exported. Note 1: You can also include a full file path in the Filename argument to save the PDF to a specific folder. The macro below does that for you, faster and easier. PageSetup.FitToPagesWide = FitToPagesWide This particular macro will print the currently active Excel sheet to a PDF called mydata.pdf and it will be saved in the current folder. For 2007 and up: In excel 2007 there is a built-in option: File / Save & Send / Create PDF & XPS Document. PasteSpecial Format:="Bitmap", Link:=False, DisplayAsIcon:=False Set ws = Workbooks.Add(xlWBATWorksheet).Worksheets(1) Keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0 Keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0 Keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0 Keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0 Optional FitToPagesWide As Integer = 1) As Boolean Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, _īyVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As LongPtr)ĭeclare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _īyVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)įunction WindowToPDF(pdf$, Optional Orientation As Integer = xlLandscape, _
0 Comments
Leave a Reply. |