Well I decided to just make my default printer the thermal printer so the userform prints without issue as a label, and other programs still allow the choice of printer before printing...except for other Microsoft programs like IE. If I leave the default printer as the thermal and print something from IE, even if I select a different printer, it keeps the page size as the thermal size. Based on that, its obviously all connected to windows API.
I went ahead and coded excel's vba to take a screenshot of the userform, paste on a new page and print to a desired printer, but the window of the userform prints as well. Also, despite having FitToPage set at 1, the print is very small. Here's the current code I have for my userform commandbutton that prints:
Private Sub CommandButton1_Click()
Dim strPrintArea
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
ActiveSheet.PageSetup.Orientation = xlPortrait
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.Shapes(1).Select 'Will always be Shape 1
With Selection 'Get print area of picture
strPrintArea = .TopLeftCell.Address & ":" & .BottomRightCell.Address
End With
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
With ActiveSheet.PageSetup
.PrintArea = strPrintArea 'Set Print Area
.PrintGridlines = False
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlPortrait
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
End With
Application.Dialogs(xlDialogPrinterSetup).Show
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWindow.Close False
End Sub
How can I make the either the screenshot or the pasted image of the screenshot only print the non-window userform? Similar to what userform.printform does.
Also, how can I scale the image to fit the correct paper size since FitToPage isn't working right?
Bookmarks