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.

Visio Guy

I just looked at Visio's print dialog/backstage panel. It doesn't support the ranges like Word or Adobe Reader do.

So temporary conversion to background seems like it might do the trick.

One question I had: "Does setting a page to background and then back again mess up the page order for the document?"

The answer is "Yes", since making a page a background sends it to the end of the page list.

So your code should add a user cell to any page that it flips between background/foreground, noting the "User.LastForegroundPageIndex". That way, the code can restore the page indices when the printing is done.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

More über-nerd notes:

You can set the NonPrinting cell for a page, but it doesn't seem to do anything.

I don't think this cell displays in the ShapeSheet, but you can get to it via automation, e.g.:

Visio.ActivePage.PageSheet.CellsU("NonPrinting").FormulaU = "TRUE"

Visio doesn't seem to respect this cell, even though it technically exists. That is probably why it is hidden from the ShapeSheet UI. There are a lot of cells that appear to be inherited from some sort of base class, but the page object overrides them. For example Width and Height can be set for a page, but only PageWidth and PageHeight have any effect.
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

The page ID stays the same, but the index changes when a page is made a background or back to foreground.
Electronic and Electrical engineering, business and software stencils for Visio -

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

dmac101

Thanks for the suggestions.

At this point I would prefer to keep going on the current path as I believe that I am almost there.
I have narrowed this down to the UIVisibility field in the page shapesheet.
Below are the steps I have taken to determine this.

  • add "MsgBox par.PageSheet.Cells("UIVisibility").FormulaU" before if statement in code
  • response back in msgbox is "TheDoc!User.ExWks_Hidden" , I am storing the visibility for each page in it own cell within TheDoc shapesheet
I would have thought that it would have displayed the 1 or 0 that is in the "TheDoc!User.ExWks_Hidden" cell rather than the cell name but maybe it cant evaluate past the first cell.
  • I have then replaced the cell reference in the UIVisibility cell for one of the pages for both a 1 & 0 but the page does not move to the background.
  • I then realized that the variable declared for the page was not the same variable being used in the if statement.
    This has been rectified and now if I change the UIVisibility cell from a reference to TheDoc to a 1 or a 0 I can get it to work.
Is there any way to treat the cell reference I have in the UIVisibility cell as the end value for the "If par.PageSheet.Cells("UIVisibility").FormulaU = 1" statement?

dmac101

I have sorted out the print by using a user cell on each page with =SETF(GetRef(ThePage!UIVisibility),TheDoc!User.StLoc_hidden)
that way the UIVisibility has a value rather than a formula and the VBA code now works fantastically.
I agree, that when pages are pushed to the background and then pushed to foreground the change of order is a complete pain. This is now where i am focued

dmac101

Hi Guys,
I am struggling trying to work out how to set the page index.

My approach is to manually set the index in a user cell of the page sheet.
then when the code runs on each page to bring to the foreground the index cell is looked up and value is set into page index.
This is what I have got so far but the page order does not change.
Any suggestions?


Sub bb(sh As Shape)
Dim par As Page
Dim pgindx As String
Set par = sh.Parent
If par.PageSheet.Cells("UIVisibility").FormulaU = 1 Then
par.Background = True ' make current page as background
Else
par.Background = False ' make current page as foreground
pgindx = par.PageSheet.CellsU("PageIndex")
par.Index = pgindx
End If
End Sub

wapperdude

#21
Something like...
ActiveDocument.Pages.ItemU("Page-1").Index = 2 

where "Page-1" is the pagename of the page you want to set the order. 

I created a 3 page document.  Used the following code to convert 1st page to background, and then back to foreground.  Then, without touching the Index structure, I moved named page = "Page-2" to 3rd place in order.  Finally moved "Page-1" to first position.  All worked well.

It's unclear if you need to set pgindx.  Use "par" to get the pagename and use the value of the PageSheet cell as the desired numerical value for ".index" = numerical value.



Sub ShflPgs()
   
'Convert Page-1 to background.
    ActiveWindow.Page = ActiveDocument.Pages.ItemU("Page-1")
    ActivePage.Background = True
    ActivePage.BackPage = ""
   
'Convert background to foreground page
    ActivePage.Background = False
   
'Change Positional order of Page-2 without updating Index count
    ActiveDocument.Pages.ItemU("Page-2").Index = 3
   
'Reset positional order of Page-1
    ActiveDocument.Pages.ItemU("Page-1").Index = 1
   
End Sub
Visio 2019 Pro

dmac101

Thanks wapperdude.
I was able to change the page index to a specific number using par.index = x, but when i try and pull the user cell "PageIndex" from the page shapesheet and substitute it, i cant get it to work.

I am calling this routine from each page only when the UIVisibility changes for the page.

Sub bb(sh As Shape)
Dim par As Page
Set par = sh.Parent
If par.PageSheet.Cells("UIVisibility").FormulaU = 1 Then
par.Background = True ' make current page as background
Else
par.Background = False ' make current page as foreground
par.Index = par.PageSheet.CellsU("PageIndex") ' set page index to page shapesheet user.PageIndex
'par.Index = 4
End If
End Sub

dmac101

Looks like a silly mistake on my side it should be
par.Index = par.PageSheet.CellsU("user.PageIndex") ' set page index to page shapesheet user.PageIndex
This seems to work somewhat but not all of the pages are in the correct order. I suspect it is to do with the order in which they are being set. Ie if a page is being set to an index of 4, then another is being set to index of 2 it may be pushing the 4 to 5. Still investigating anyway.

wapperdude

Yep.  When inserting, start at top of order and work down.  Anything already in place gets pushed down relative to top spot.  Think of someone cutting in line.

The other thing, .formula is used to assign something to a cell.  Use .result to fetch from a cell.
Visio 2019 Pro