Microsoft Office Tutorials and References
In Depth Information
Printing a UserForm
MsgBox "Done !", vbInformation¶
'Restore screen updating¶
Application.ScreenUpdating = True¶
End Sub¶
The following code should be placed in a UserForm named ‘fmPrint’. The
example file has the form with the code already in it. To create from scratch,
use Insert | UserForm from the menu bar and design the form with the
controls that should be on it. This form has three labels, two text boxes, two
command buttons, and a combo box arranged as indicated in the code:
Exl
View the Appendix to learn how to store this procedure
in a UserForm.
Option Explicit¶
' * * * * *¶
Private Sub BCancel_Click()¶
Unload Me¶
End Sub¶
' * * * * *¶
Private Sub BPrint_Click()¶
PrintForm¶
End Sub¶
' * * * * *¶
Private Sub UserForm_Initialize()¶
'Set the orientation options¶
cbOrientation.List = Array("Portrait", "Landscape")¶
'Choose 'Portrait'¶
cbOrientation.ListIndex = 0¶
'Default margins¶
txLeft.Value = 1¶
txTop.Value = 1¶
End Sub¶
The program needs all the code from the first section, except for the macro
‘Sample’. The UserForm is only used in the sample to demonstrate how to use
the code.
In the section 'Change this code to modify the print setup', modifying different
things like margins, paper orientation, and paper size—in other words, the
same settings that you modify to print a Microsoft Word document—can be set
as desired.
Search JabSto ::




Custom Search