print a Userform

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
826
Office Version
  1. 365
Platform
  1. Windows
Hi
Is there a way to print a Userform?
I made one using about 25 command buttons and would like to make a hard copy
I probably would only have to do it once

mike
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
VBA Code:
Option Explicit

Private Sub CommandButton1_Click()
Dim RetStat
    CommandButton1.Visible = False
    RetStat = Application.Dialogs(xlDialogPrinterSetup).Show
    If RetStat Then Me.PrintForm
    Unload Me
End Sub
 
Upvote 0
Hi logit
Thanks
I changed the coding for commandbutton1 and it printed out the form except that command button 1 was missing.
I also tried changing commandbutton 2 (changing your code to ...2...) and still got commandbutton1 missing

Hi DAve
I tried that after the userform was up and got nothing

I can work around missing one image on the form

Thanks

mikke
 
Upvote 0
Print Form n Save As XLSX.xlsm


User Form Code :


VBA Code:
Option Explicit

'Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
'   bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
'Private Declare PtrSafe Sub keybd_event Lib "User32" _
'    (ByVal bVk As Byte, ByVal bScan As Byte, _
'     ByVal dwFlags As Long, ByVal dwExtraInfo As LongPtr)
    
#If VBA7 Then
    Private Declare PtrSafe Sub keybd_event Lib "user32" _
        (ByVal bVk As Byte, ByVal bScan As Byte, _
         ByVal dwFlags As Long, ByVal dwExtraInfo As LongPtr)
#Else
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
       bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
#End If
    
    
    
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12 '''

Private Sub AltPrintScreen()
        keybd_event VK_MENU, 0, 0, 0
        keybd_event VK_SNAPSHOT, 0, 0, 0
        keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
        keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
End Sub
Private Sub CommandButton1_Click()
Call AltPrintScreen
    DoEvents
    Application.Wait Now + TimeSerial(0, 0, 1)
    Worksheets("Sheet1").Range("B3").PasteSpecial
    Unload Me
End Sub


Command Button On Form :

Code:
Option Explicit

Sub shwfrm()
    UserForm1.Show
End Sub

Sub CommandButton1_Click()
Dim h1 As Object

    Set h1 = Sheets.Add
    h1.PageSetup.Orientation = xlLandscape
    Application.SendKeys "(%{1068})"
    DoEvents
    h1.Paste
    h1.PrintOut Copies:=1, Collate:=True
    Application.DisplayAlerts = False
    h1.Delete
End Sub
 
Upvote 0
hi Logit,
thanks, I'll try your code, but it won't be till i have time next week.

mike
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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