Print a userform in landscape

TheBeefMan

New Member
Joined
Sep 20, 2007
Messages
7
Please can anyone help me print a userform automatically in landscape mode? I just can't seem to get the code right. I would appreciate any leads.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Assuming your userform is named "UserForm1", you might be able to get away with this simple one-liner to print the image of that userform:

UserForm1.PrintForm

In that example, the userform does not need to be open or active.



If you truly want to make sure the userform's image is printed in landscape, here is one way, which will involve said userform being open.

In a fresh new standard module such as the kind you put macros and UDFs in, paste in this code:


Code:
Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Public Const VK_SNAPSHOT = &H2C


In the userform of interest's module (again, assuming it is named UserForm1 because you did not say), paste in this code which would be triggered when you click a command button named "CommandButton1" that you have placed on that userform:

Code:
Private Sub CommandButton1_Click()
   Application.ScreenUpdating = False
   keybd_event VK_SNAPSHOT, 1, 0, 0
   Workbooks.Add 1
   ActiveSheet.Range("A1").Select
   Application.Wait Now + TimeValue("00:00:01")
   ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False, DisplayAsIcon:=False
   With ActiveSheet
      .PageSetup.Orientation = xlLandscape
      .PageSetup.LeftHeader = "Userform1"
      .PrintOut
   End With
   ActiveWorkbook.Close False
   Unload Me
   Application.ScreenUpdating = True
End Sub
 
Upvote 0
I can actually contribute something!!!

To print the userform centered, both horizontally and vertically, add the following:

.PageSetup.CenterHorizontally = True
.PageSetup.CenterVertically = True


Wow, I actually contributed something instead of always taking. Feels good!
 
Upvote 0

Forum statistics

Threads
1,214,866
Messages
6,121,996
Members
449,060
Latest member
mtsheetz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top