Microsoft Office Tutorials and References
In Depth Information
Printing a UserForm
' * * * * *¶
Sub Sample()¶
End Sub¶
' * * * * *¶
Sub PrintForm()¶
'Variable declaration¶
Dim wdApp As Object 'Word.Application¶
Dim wdDoc As Object 'Word.Document¶
'Simulate pressing Alt + Print Screen.¶
'because of this, the UserForm *must* be visible¶
'at the time the code is run¶
'Press Print Screen¶
keybd_event VK_SNAPSHOT, 1, 0, 0¶
'Give the computer time to process the screen¶
'(may need to be changed)¶
Application.Wait Now + TimeSerial(0, 0, 1)¶
'Turn off screen updating¶
Application.ScreenUpdating = False¶
'Create a word process¶
Set wdApp = CreateObject("Word.Application")¶
'Create a new document¶
Set wdDoc = wdApp.Documents.Add()¶
With wdDoc¶
'Change the print settings¶
With .PageSetup¶
'Change this code to modify the print setup¶
.Orientation = IIf(fmPrint.cbOrientation.Value = "Portrait", _¶
0, 1) 'wdOrientPortrait = 0¶
'wdOrientLandscape = 1¶
.LeftMargin = wdApp.InchesToPoints(Val(fmPrint.txLeft.Value))¶
.TopMargin = wdApp.InchesToPoints(Val(fmPrint.txTop.Value))¶
End With¶
'Paste the image¶
'Print the document¶
'Give Word time to send the document to the printer¶
Do While wdApp.BackgroundPrintingStatus > 0¶
'Close it without saving changes¶
.Close SaveChanges:=False¶
End With¶
'Quit Word¶
wdApp.Quit SaveChanges:=False¶
'Kill the variables and free memory¶
Set wdDoc = Nothing¶
Set wdApp = Nothing¶
'Done !¶
Search JabSto ::

Custom Search