A print function to set, and written by someone else, Jiehuaxianfo, but did not find what API function is used, copied down Public Enum PrinterOrientationConstants OrientPortrait = 1 OrientLandscape = 2End EnumPrivate Declare Function GetVolumeInformation Lib _ "kernel32.dll" Alias " GetVolumeInformationA "(ByVal _ lpRootPathName As String, ByVal lpVolumeNameBuffer As _ String, ByVal nVolumeNameSize As Integer, _ lpVolumeSerialNumber As Long, lpMaximumComponentLength _ As Long, lpFileSystemFlags As Long, ByVal _ lpFileSystemNameBuffer As String, ByVal _ nFileSystemNameSize As Long) As LongPrivate Type DEVMODE dmDeviceName As String * 32 dmSpecVersion As Integer dmDriverVersion As Integer dmSize As Integer dmDriverExtra As Integer dmFields As Long dmOrientation As Integer dmPaperSize As Integer dmPaperLength As Integer dmPaperWidth As Integer dmScale As Integer dmCopies As Integer dmDefaultSource As Integer dmPrintQuality As Inte ger dmColor As Integer dmDuplex As Integer dmYResolution As Integer dmTTOption As Integer dmCollate As Integer dmFormName As String * 32 dmUnusedPadding As Integer dmBitsPerPel As Integer dmPelsWidth As Long dmPelsHeight As Long dmDisplayFlags As Long dmDisplayFrequency As LongEnd Type
Private Type Printer_Defaults PDATATYPE AS STRING PDEVMODE AS Long DesiredAn Longend Type
Private Type PRINTER_INFO_2 pServerName As Long pPrinterName As Long pShareName As Long pPortName As Long pDriverName As Long pComment As Long pLocation As Long pDevMode As Long pSepFile As Long pPrintProcessor As Long pDatatype As Long pParameters As Long pSecurityDescriptor As Long Attributes As Long Priority As Long DefaultPriority As Long StartTime As Long UntilTime As Long status As Long cJobs As Long AveragePPM As LongEnd TypePublic Const DMPAPER_A5 = 9Public Const DM_IN_BUFFER As Long = 8Public Const DM_OUT_BUFFER As Long = 2Public Const DM_ORIENTATION As Long = & H1Public Const DM_PAPERSIZE = & H2 &
Public Const PRINTER_ACCESS_ADMINISTER As Long = & H4Public Const PRINTER_ACCESS_USE As Long = & H8Public Const STANDARD_RIGHTS_REQUIRED As Long = & HF0000Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
Public Declare Sub CopyMemory Lib "kernel32" Alias "RTLmoveMemory" (HPVDest As Any, HPVSource As Any, Byval CBCopy As Long)
Public Declare Function OpenPrinter Lib "Winspool.drv" Alias "openprintera" (Byval Pprintera "(PDEFAULT AS ANY) AS Long
Public Declare Function Closeprinter Lib "Winspool.drv" (Byval Hprinter As Long) As Long
Public Declare Function DocumentProperties Lib "winspool.drv" Alias "DocumentPropertiesA" (ByVal hwnd As Long, ByVal hPrinter As Long, ByVal pDeviceName As String, pDevModeOutput_ As Any, pDevModeInput As Any, ByVal fMode As Long) As Long
Private Declare Function GetPrinter Lib "winspool.drv" Alias "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Any, ByVal cbBuf As Long, pcbNeeded As Long) As LongPrivate Declare Function SetPrinter Lib "winspool.drv" Alias "Setprintera" (Byval Hprinter As Long, Byval Level As Long, Pprinter As Any, BYVAL Command As long) AS Long
Function SetDefaultPrinterOrientation (ByVal eOrientation As PrinterOrientationConstants, Optional ByVal mPageSize As Integer = -1) As Boolean Dim bDevMode () As Byte Dim bPrinterInfo2 () As Byte Dim hPrinter As Long Dim lResult As Long Dim nSize As Long Dim sPrnName As String Dim dm As DEVMODE Dim pd As PRINTER_DEFAULTS Dim pi2 As PRINTER_INFO_2 'get the printer device name sPrnName = Printer.DeviceName' due to be called SetPrinter, so 'if it is in the NT requires PRINTER_ALL_ACCESS pd.DesiredAccess = PRINTER_ALL_ACCESS' get the name of the printer handle If OpenPrinter (sPrnName, Hprinter, Pd) THEN 'Get the byte of the Printer_info_2 Structure Call Getprinter (Hprinter, 2 &, 0 &, 0 &, Nsize) Redim BprinterInfo2 (1 to nsize) as Byte Lresult = Getprinter (Hprinter, 2, BprinterInfo2 (1), NSize , NSIZE 0) ReDim bDevMode (1 To nSize) If pi2.pDevMode Then Call CopyMemory (bDevMode (1), ByVal pi2.pDevMode, Len (dm)) Else Call DocumentProperties (0 &, hPrinter, sPrnName, bDevMode (1), 0 &, DM_OUT_BUFFER ) Endiff COLL COPYMEMORY (DM, BDEVMODE (1), LEN (DM) with DM 'Sets new Trend .dmorientation = ERITATION .dmfields = EMPTY IF MPAGESIZE <> -1 Then .dmpapersize = Mpagesize End IF' Put the paper size Set to A5, please change the desired size .dmfields = DM_ORIEntation DM_PAPERSIZE '