Hide pages from printing

Started by dmac101, December 02, 2021, 09:13:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dmac101

Hi All,
I am working on a Visio drawing template that is linked to an external data source. I want to be able to hide and disable printing for specific pages based on the external data. I can currently manage the hide component by using TheDoc shapesheet user cells and then referencing them in each page shapesheet for the UIVisibility cell. This works exactly how I want but cant work out how to disable print on the same pages.
I have had a look through and was not able to find anything suitable. I have tried the PagesX and PagesY cells, whilst this stops the drawing from being printed, there is still a blank page. I was looking for more of a not print at all option.
Does anyone have some ideas on how to achieve this?
I really suck at VBA so would prefer to avoid this option if feasible.

Thanks
dmac101


dmac101

Can pages be sent to the background using the page shapesheet?

Surrogate

Quote from: dmac101 on December 03, 2021, 06:58:37 AM
Can pages be sent to the background using the page shapesheet?
IMHO, you cant do it via shapesheet environment !
Only via user interface or your custom code.

dmac101

mmmm custom code. This is something have been avoiding due to my lack of knowledge. Looks like I am going to get my hands dirty. Any suggestions on where to start?

Surrogate

#5
In this post from 2012 you can find my old code
Sub hidepages ()
Dim pg As Page 'defining the current page
Dim pgn As String' defining the name of the current page
Dim wn As Window 'defining the current window
For Each pg In ActiveDocument.Pages' iterating over the pages of the document
pgn = pg.Name' assigning the name of the page
s = MsgBox ("Hide page" & pgn, vbYesNo, "Hide pages") 'receive a response to hide the page
If s = 6 Then
pg.Background = True ' make current page as backgound
pg.CellsSRC (visSectionObject, visRowPage, visPageUIVisibility) .FormulaU = "1"' hide the current page
Else
pg.Background = False ' make current page as foregound
pg.CellsSRC (visSectionObject, visRowPage, visPageUIVisibility) .FormulaU = "0"' show the current page
End If
Next pg 'go to the next page
End Sub

dmac101

Thanks Surrogate. The initial code had compile error. I removed the spaces before the FormulaU this now runs and i get the MsgBox but when i make a selection it has an "Object doesn't support this property or method" error'. However the page is moved to the background when i select Yes, it just doesn't iterate through the pages. I can now see how it works and will attempt to integrate into my drawing.

Thanks for you help

Surrogate

Quote from: dmac101 on December 03, 2021, 08:31:36 PM
The initial code had compile error.
You are right ! I didn't test code, just modify at my phone code which was written about decade years ago. Sorry!
Quote from: dmac101 on December 03, 2021, 08:31:36 PMit just doesn't iterate through the pages.
Just now i tested this code, it works at my side
Sub hidepages()
Dim pg As Page 'declaring the current page
Dim pgn As String ' defining the name of the current page
Dim wn As Window 'defining the current window
For i = ActiveDocument.Pages.Count To 1 Step -1  ' iterating over the pages of the document
Set pg = ActiveDocument.Pages(i) 'defining the current page
pgn = pg.Name ' assigning the name of the page
s = MsgBox("Hide page " & pgn, vbYesNo, "Please select pages for hide!")  'receive a response to hide the page
If s = 6 Then
pg.Background = True ' make current page as backgound
pg.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageUIVisibility).FormulaU = "1" ' hide the current page
Else
pg.Background = False ' make current page as foregound
pg.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageUIVisibility).FormulaU = "0" ' show the current page
End If
Next i 'go to the next page
End Sub


dmac101

Thanks That works fine for me now.
I had already set the page visibility with linked external data, so i have modified your code above to set background based on each pages UIVisibility cell. Now i am just trying to work out how best to trigger this. I have set to page change but it does not work when the coverpage is updated by linking to another data row. Any suggestions?

Private Sub Document_PageChanged(ByVal Page As IVPage)
Dim pg As Page 'declaring the current page
Dim pgn As String ' defining the name of the current page
Dim wn As Window 'defining the current window
Dim vsoCell As Visio.Cell
Set pg = ActivePage
For i = ActiveDocument.Pages.Count To 1 Step -1  ' iterating over the pages of the document
Set pg = ActiveDocument.Pages(i) 'defining the current page
Set vsoCell = pg.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageUIVisibility)
If vsoCell = 1 Then
pg.Background = True ' make current page as backgound
Else
pg.Background = False ' make current page as foregound
End If
Next i 'go to the next page
End Sub



Surrogate

Quote from: dmac101 on December 05, 2021, 11:58:02 PM
I had already set the page visibility with linked external data
I.e. in your case UIVisibility managed by external data ?  :o

Surrogate

Document_PageChanged event dont trigerred when you change page visibility ! it is dont fired even when you change page size...

Surrogate

#11
My suggestion use DEPENDSON function for triggered UIVisibility changes!
As first you need add user-defined cell with formula for each Page
CALLTHIS("Thisdocument.bb")+DEPENDSON(UIVisibility)
Also you need change your code
Sub bb(sh As Shape)
Dim par As Page
MsgBox sh.Name
Set par = sh.Parent
If par.PageSheet.Cells("UIVisibility").FormulaU Then
pg.Background = True ' make current page as background
Else
pg.Background = False ' make current page as foreground
End If
End Sub



After you hide and make page as background you cant see it in user interface !
You can navigate into document with keys Ctrl+/Ctrl+PgUp  :o

dmac101

Thanks Surrogate,
For some reason the pages that are hidden are sill printable.
I have modified the code with MsgBox's to provide debug info
The "par set" msgbox appears but nothing after that.



Sub bb(sh As Shape)
Dim par As Page
MsgBox sh.Name
Set par = sh.Parent
MsgBox "par set"
If par.PageSheet.Cells("UIVisibility").FormulaU Then
pg.Background = True ' make current page as background
MsgBox "Make Page Background"
Else
pg.Background = False ' make current page as foreground
MsgBox "Make Page Foreground"
End If
End Sub


Visio Guy

The print dialog also allows you to print specific pages, e.g. 1-3,5,7,9-12.

I wonder if there is a way to send info to that field in the print dialog using code? If so, you could mark pages as "not to print" using a shape or some page-shapesheet cell/value. Then you could have a special My Print button that figures out which pages should not be printed. This code would send the correct syntax to the print dialog.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Paul Herber

Quote from: Visio Guy on December 07, 2021, 03:52:38 PM
I wonder if there is a way to send info to that field in the print dialog using code?

Should be possible using SendKeys.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/