News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Quickly toggle "non-printing" shape property

Started by David.P, July 29, 2014, 01:33:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

David.P

Hi forum,

what is the quickest (or is there a quicker than below) way to switch between the "printing/non-printing" status of a shape? I tried to record a VBA macro but it seems to work only on the shape where it has been recorded, not on other shapes.



Thanks for any help
David.P
Visio 2003 for production
Visio 2019

Jumpy

Quote from: David.P on July 29, 2014, 01:33:31 PM
I tried to record a VBA macro but it seems to work only on the shape where it has been recorded, not on other shapes.

What did you expect?

Perhaps you can show us the code generated by your macro recorder, and we can show you which line of code to change so your code works on a selected shape or every selected shape (and not only on Shape 42).

David.P

Hmm, I expected the macro to work on any current selection (like in all my Word macros)....

Anyway, here's the code.
Sub Shape_nicht_druckbar()
' Tastenkombination: Strg+q
    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope("Verhaltenseigenschaften")
    Application.ActiveWindow.Page.Shapes.ItemFromID(92).CellsSRC(visSectionObject, visRowMisc, visNonPrinting).FormulaU = "TRUE"
    Application.EndUndoScope UndoScopeID1, True

End Sub


Thanks
David
Visio 2003 for production
Visio 2019

Yacine

#3
QuoteHmm, I expected the macro to work on any current selection (like in all my Word macros)....
Interesting comment. I don't code that much in Word myself, so that I did not realize that other applications do it better than Visio.  ;)

That would however explain why this same question is asked over and over again in the forum.

The trick is to replace the
Application.ActiveWindow.Page.Shapes.ItemFromID(92)
by
ActiveWindow.Selection (1)
This is the shortest form that you can use.

Safer versions would check if at least one shape is selected
if ActiveWindow.Selection.count>0 then
  'your code here
end if


If your code is meant to handle only one shape then:
If ActiveWindow.Selection.Count > 1 Then
    MsgBox "Please select only one shape."
Else
    'your code here
End If


Your code may as well be capable of handling several shapes at once, then:
For Each shp In ActiveWindow.Selection
    'your code here
Next shp


@Jumpy, sorry for the inteference. I'm not only bored in the holliday time, but also wanted to set up a "re-usable" answer to this question. Entschuldigung.
Yacine

wapperdude

QuoteI'm not only bored in the holliday time...

Well, that explains a lot!  But, Mr. Boredom, your solution is incomplete!   ???  You didn't include the possibility to let the code loop thru every shape on the page and set it to non-printing.  Yeah.  Why would you do that?   :o  Perhaps to prevent people from making hardcopy copies.  I dunno.   ::)
Visio 2019 Pro

David.P

That's great guys! Thanks very much Yacine. I'll try the code and report back asap.
Visio 2003 for production
Visio 2019

Yacine

#6
QuoteWell, that explains a lot!  But, Mr. Boredom, your solution is incomplete!     You didn't include the possibility to let the code loop thru every shape on the page and set it to non-printing.
I plead guilty...

Looping through every shape would be as easy as:
For Each shp In ActivePage.Shapes 'note the difference to activewindow
    'your code here
Next shp


Now, how to access also the sub-shapes? You'll need two routines:
Sub MainLoop()
    For Each shp In ActivePage.Shapes 'note the difference to activewindow
        actualProcessingAndDeeperLoop shp
    Next shp
End Sub


Sub actualProcessingAndDeeperLoop(shp As Visio.Shape) 'this one is recursive
    'do something with the shape

    'then handle it's sub-shapes
    For Each subShp In shp
        actualProcessingAndDeeperLoop subShp
    Next subShp
End Sub


... and of course " 'your code here" would then be substituted by
shp.CellsSRC(visSectionObject, visRowMisc, visNonPrinting).FormulaU = "TRUE"

Did I forget an important case?

Well, you may want to loop through the shapes in all the pages of your document, then:

Sub loopThroughAllPages()
Dim tempPg As Variant

    Set tempPg = ActivePage
    For Each pg In ActiveDocument.Pages
        ActiveWindow.Page = visDocument.Pages(pg).Name
        'check for background page
        If Not pg.Background Then
            For Each shp In ActivePage.Shapes
                'your code here
            Next shp
        End If
    Next pg
    'and back to the current page
    ActiveWindow.Page = visDocument.Pages(tempPg).Name
End Sub

Yacine

wapperdude

 ;D   :o   :D   :P   ???   :D

You really are bored!

Think you did cover every possibility!  But, no more caffeine for you!
Visio 2019 Pro

David.P

Thanks again Yacine, that macro now works beautifully on any selected shape.
Visio 2003 for production
Visio 2019

Jumpy

Quote from: Yacine on July 29, 2014, 05:27:44 PM
QuoteHmm, I expected the macro to work on any current selection (like in all my Word macros)....
Interesting comment. I don't code that much in Word myself, so that I did not realize that other applications do it better than Visio.  ;)

That would however explain why this same question is asked over and over again in the forum.

I knew that the macro editor in Word and Excel often works with the selection (and I'm often annoyed by it, because in Excel-VBA it is often slower if you first select sth. and then do sth. with an object, instead of doing the sth. to the object directly). But I did not consiously make the connection, that Visio's behaviour is different, and extremly annoing, too, because in Visio I would like the macro recorder to work with a selection.

So thanks for the insight.

Quote from: Yacine on July 29, 2014, 05:27:44 PM
@Jumpy, sorry for the inteference. I'm not only bored in the holliday time, but also wanted to set up a "re-usable" answer to this question. Entschuldigung.

No need to be sorry. Because I'm all alone in the office, everyone and his brother having holidays, I'm quite the opposite of bored and only can spend 5 quick minutes a day in the forum, so your answer came much faster and is much richer than mine would have been.

dirkasarus-rex

This 'reusable' code works to iterate through grouped and ungrouped shapes.

Thanks Yacine for posting this!   8)

David.P

Ok guys, I now haven't used my non-printing shape property macro:

Sub Make_shape_not_printable()
' Keyboard Shortcut: Ctrl+q
    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope("Verhaltenseigenschaften")
    ActiveWindow.Selection(1).CellsSRC(visSectionObject, visRowMisc, visNonPrinting).FormulaU = "TRUE"
    Application.EndUndoScope UndoScopeID1, True
End Sub


...for a while, and it seems to have lost its keyboard shortcut "ctrl+q" that I had assigned to it.

Is there a way to re-assign that keyboard shortcut like, permanently to this macro?
Visio 2003 for production
Visio 2019

wapperdude

In V2007, to restore the shortcut key:
  Bring up the macros window (Alt+F8) or Tools>macros.  Select (high light) the macro from the list and then press Options...  Enter the desired key in the box.  That's it.

As far as making it permanent, not sure if that's possible, but, ordinarily, I don't think it ought to disappear unless something was done to cause it to be removed.

Wapperdude
Visio 2019 Pro

David.P

Thank you very much Wapperdude,

will try that and report back if it worked.

Cheers David.P
Visio 2003 for production
Visio 2019

David.P

Sorry for taking this long...

Actually I think that this worked. However now, after reinstalling everything including Windows and Visio, I can't assign my keyboard shortcut to my macro anymore.

If I try, Visio tells me that I "should (!) assign a different hotkey to the macro because this key is already assigned to a different macro". However, I can't find a macro that has this shortcut, and I can't remove the shortcut from wherever it might be assigned to currently.

Thanks for any ideas regarding this,

Cheers
David
Visio 2003 for production
Visio 2019

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 438 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1275KB.
Tokens: post-login.
Cache hits: 13: 0.00116s for 26,767 bytes (show)
Cache misses: 2: (show)
Queries used: 15.

[Show Queries]