Me.PrintForm -> landscape

H

Henry

I've set up my form, filled it in, and now I want to print it.
Me.PrintForm does print the form but it prints portrait.
I want it printed landscape.
Any one know how to do it?

Henry
 
J

Jim Cone

Henry,

Show the form. Copy it using Alt+Prt Scrn keys.
Dismiss the form.
Paste into a blank Excel sheet. Print it the way you want.

Jim Cone
San Francisco, USA


I've set up my form, filled it in, and now I want to print it.
Me.PrintForm does print the form but it prints portrait.
I want it printed landscape.
Any one know how to do it?
Henry
 
H

Henry

Jim,
Thanks, but that's not what I want.

This program is for children and everything must be as automatic as
possible.
There's a "Print" button on the form which I use to print the form.
At the moment I've got.

Sub PrintButton_Click()
Me.PrintForm
End Sub

That prints the form, but portrait style.
I need to adjust the code to make it print landscape.

Henry
 
D

Dave Peterson

This was posted by Tom Ogilvy:

Modification of code originally posted by
"Orlando Magalhães Filho" <[email protected]>

Modified to capture just the userform (not the whole window).

In a general module:

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 = 44
Public Const VK_LMENU = 164
Public Const KEYEVENTF_KEYUP = 2
Public Const KEYEVENTF_EXTENDEDKEY = 1


Sub Test()
UserForm1.Show
End Sub


In the userform module:

Private Sub CommandButton1_Click()
' keybd_event VK_SNAPSHOT, 0, 0, 0
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
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWorkbook.Close False
End Sub

I added a line that changed the orientation to landscape.
 
H

Henry

Thanks Dave, Tom and Orlando.
What a lot of code for what seemed a simple problem.
I'll try it later.

Once again, thanks.

Henry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top