I'm trying to create a VBA code to print my drawings in SolidWorks. I've designed a UserForm with buttons, where each button corresponds to a sheet size (A4 Portrait and Landscape, A3, A2 and A1).
Please note that the drawing is already open and active. I want to use a shortcut to run my VBA code, and when I do, my UserForm should appear so I can choose my desired sheet size.
Below is my code; it doesn't show any errors, but it's not working. The code is for printing only in A4 sheet size; it works when I use it for other sheet sizes.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swPageSetup As SldWorks.PageSetup
Dim NameFile As String
Dim Printer As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swPageSetup = swModel.PageSetup
NameFile = swModel.GetTitle
Printer = "Brother HL-5470DW series Printer"
With swPageSetup
.PrinterPaperSize = 9
.Orientation = 1
.HighQuality = True
.Scale2 = False
.DrawingColor = 1
End With
swModelDocExt.PrintOut4 Printer, NameFile, swPageSetup
Here is a macro that does it. In your code, third argument to PrintOut4 is wrong. It needs to be the PrintSpecification object