#1
|
|||
|
|||
Print Multipage Userform in Landscape
I have a Word (not Excel) multipage userform (5 pages). One client wants to have "images" of each of the pages to write on by hand - yes really! I have a command button to print the entire userform with the following sub:
Private Sub CommandButton1_Click() For i = 0 To 4 Me.MultiPage1.Value = i Me.PrintForm Next End Sub This of course prints each page in portrait rather than landscape and gets cut off. I could probably change my printer defaults, but for my clients who want to print, I need some code as they won't be able to change their defaults easily. Does anyone have VBA code to add to this sub to get each page in landscape? I am unable to use =wdOrientLandscape, etc., since we aren't talking about word docs; rather the userform itself. Thanks. |
#2
|
||||
|
||||
Sounds to me rather like you need to do something like a screen capture of the userform and paste it into the underlying document on a landscape formatted page.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
I have seen some code for an Excel userform but doesn't seem applicable for a Word one.
|
#4
|
||||
|
||||
If you have code that prints a userform in landscape mode for Excel without pasting anything to a worksheet, the same code would almost certainly work in Word.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
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 |
#6
|
||||
|
||||
As I said in post #4, the code would work for Word if it didn't paste anything to an Excel workbook, but that's precisely what your code does. In fact, most of it is concerned with the worksheet formatting. As I also suggested you might need to do in post #2, the code basically does a screen capture of the userform and pastes it. For a single multi-page userform, that would take much less time to do manually than it would take for anyone to write the code. Is there a reason for not doing that?
FWIW, your code would only process the page of a userform it's attached to.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
I appreciate that your reply reinforces what I already know - that this code will work for excel but not Word. I have no idea how to change it for a Word user form. I also realize the code is for a single page user form; however, as the initial question indicated, I have a multipage (5) user form, and had initial code to print all pages - but in portrait. I have NO IDEA how to modify the code to make it work with a Word document rather than an Excel document. I also indicated in my prior posts that this is being done for users of the user form and will be done more than once; therefore, it needs to be a command button in the form - it is not a one-time screen shot affair - and since I would need five screen shots anyway, I still cannot get there without modifying the code I have (or getting someone willing to help with this rather than just keep pointing out what I don't have).
|
#8
|
||||
|
||||
Surely, once you've taken a copy of all the pages, you can save them as a template?! There would be no reason to keep doing this for the same form...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
I cannot get a copy of each of the pages - can you actually explain how to do this? As I said part gets cut off bc it is in portrait. Further, this is a dynamic form that changes depending upon answers. I have already provided them with a data sheet that can be saved but they would like actual pics of the form - easier to give to secretary if they have to make a new set of documents with similar responses. The userform can change dramatically depending.
|
#10
|
||||
|
||||
Simply start your userform, switch to the page you want to copy, press Alt-PtrScr, close the userform, then paste the picture into Word. Not exactly difficult...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Landscape Orientation - Rotate page so top of landscape is printed on left side | swifty2010 | Word | 17 | 06-11-2022 05:50 PM |
Convert large multipage table to jpeg | idiotwind | Word Tables | 3 | 12-01-2015 03:53 AM |
Large number of landscape pages within a portrait doc--do I have to textbox by hand every landscape? | mlkmnsgrl | Word | 7 | 01-05-2015 05:19 PM |
Print 2 pages to a sheet in Landscape page orientation | Alexie | Excel | 1 | 09-18-2010 01:29 AM |
Multicolumn Multipage | makaveli89 | Word | 0 | 11-10-2008 11:52 PM |