View Single Post
 
Old 05-13-2016, 09:00 AM
mktate mktate is offline Windows 10 Office 2010 64bit
Novice
 
Join Date: Dec 2015
Posts: 26
mktate is on a distinguished road
Default Code that doesn't work

Here is Code I tried to change for a Word userform, using ActiveDocument instead of Application, but I get bugs virtually every line. I am not a coder, so then I tried to just delete what didn't have a home in a Word document, eventually getting multiple pages of the userform to print, but again in portrait, not landscape. So, if anyone can modify this code to try to get a multipage Word userform to print in landscape, I would greatly appreciate it! (I give the original code, not my attempted revisions):
Code:
Option Explicit
 
Private Declare PtrSafe Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As LongPtr)
Const VK_SNAPSHOT = 44
Const VK_LMENU = 164
Const KEYEVENTF_KEYUP = 2
Const KEYEVENTF_EXTENDEDKEY = 1
 
Private Sub CommandButton1_Click()
DoEvents
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
Workbooks.Add
Application.Wait Now + TimeValue("00:00:01")
ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False, _
DisplayAsIcon:=False
ActiveSheet.Range("A1").Select
'added to force landscape
ActiveSheet.PageSetup.Orientation = xlLandscape
 
 
With ActiveSheet.PageSetup
  .PrintTitleRows = ""
  .PrintTitleColumns = ""
End With
 
ActiveSheet.PageSetup.PrintArea = ""
 
With ActiveSheet.PageSetup
  .LeftHeader = ""
  .CenterHeader = ""
  .RightHeader = ""
  .LeftFooter = ""
  .CenterFooter = ""
  .RightFooter = ""
  .LeftMargin = Application.InchesToPoints(0.75)
  .RightMargin = Application.InchesToPoints(0.75)
  .TopMargin = Application.InchesToPoints(1)
  .BottomMargin = Application.InchesToPoints(1)
  .HeaderMargin = Application.InchesToPoints(0.5)
  .FooterMargin = Application.InchesToPoints(0.5)
  .PrintHeadings = False
  .PrintGridlines = False
  .PrintComments = xlPrintNoComments
  .PrintQuality = 300
  .CenterHorizontally = True
  .CenterVertically = True
  .Orientation = xlLandscape
  .Draft = False
  .PaperSize = xlPaperA4
  .FirstPageNumber = xlAutomatic
  .Order = xlDownThenOver
  .BlackAndWhite = False
  .Zoom = False
  .FitToPagesWide = 1
  .FitToPagesTall = 1
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWorkbook.Close False
End Sub

Last edited by macropod; 05-13-2016 at 03:42 PM. Reason: Added code tags & formatting
Reply With Quote