Print a single page in VBA

Hello

 

I would like to print only the active sheet in vba ? Because there it prints all the sheets ...

This would suit me enormously

 

Currently I'm printing with this: (Part of the code)

 

    Set ps = Model.PageSetup
    ps. PrinterPaperSize = Model_PaperSize
    ps. Orientation = Model_Orientation
    ps. ScaleToFit = Model_ScaleToFit
   
    Model.PrintDirect

 

Thank you

You should add somewhere in your VBA before the action of printing

 

Dim swdoc As SldWorks.ModelDoc2
Dim swSheet As SldWorks.Sheet

Set swSheet = swdoc. GetCurrentSheet

 

And so it should print your active sheet

I don't see how that would solve my problem, because we never say it to the printer or in the print settings. but I'll try anyway.

I don't know if this will solve your problem. But personally I know that it prints my active page when I do so.

 

On the other hand, maybe I'm a little touchy, maybe it's badly worded on your part... In any case , I'm sure it's not voluntary on your part. But you should be careful about the tone you use through your words. :)

1 Like

Oh all my apologies, I really didn't mean that badly. I'm really sorry.

 

Regarding my problem, your solution does not solve my case.

Thank you!

1 Like

Hello

A macro is available here:

https://forum.solidworks.com/thread/64218#344104

 

2 Likes

I just downloaded it and I was able to get this code from it:

 

  For i = 0 To UBound(vSheetNames)
        If vSheetNames(i) = SheetName Then
            MsgBox ("Print" + Str(i))
            Model.Extension.PrintOut2 i + 1, 1, False, "", ""
            Exit For
        Else
            MsgBox ("Not this page")
        End If
    Next i

 

but unfortunately it doesn't work, and that's because of the "pageArray", because this code works:

  pageArray(0) = 1
  vPageArray = pageArray

  Model.Extension.PrintOut2 vPageArray, 1, False, "", ""

 

I don't understand why

Apparently putting this instead:

 

            pageArray(0) = i + 1
            pageArray(1) = i + 1
            pageArray(2) = i + 1
            pageArray(3) = i + 1
            vPageArray = pageArray

 

it works... Thank you, I'll do one-two more tries to confirm.

If you can post your full macro so that it can be used by others later, that would be nice.