Run a macro from a stencil

Started by Soundstorm, December 01, 2023, 09:54:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Soundstorm

Hi

When making revisions to documents, we add revision clouds around the revised shapes. I like to publish the documents with and without the revision clouds visable.
If the document is 1 page only, I just (un)check the print checkbox for the layer of the revision clouds. Now, if there are more pages, it seems that I have to modify this check box for each page.

So after looking around, I have found this topic:
https://www.msofficeforums.com/visio/41067-show-hide-layers-all-pages.html

And I then made the following VBA:
Sub RevisionNoPrint()
    ShowHideLayer "Revision", False
End Sub

Sub RevisionPrint()
    ShowHideLayer "Revision", True
End Sub

Public Sub ShowHideLayer(sLayerName As String, bShow As Boolean)
  Dim aPage As Visio.Page, aLayer As Visio.Layer, aCell As Visio.Cell
 
  For Each aPage In ActiveDocument.Pages
    For Each aLayer In aPage.Layers
      If aLayer.Name = sLayerName Then
        Set aCell = aLayer.CellsC(visLayerPrint)
        aCell.Formula = bShow
      End If
    Next aLayer
  Next aPage
End Sub


We also add a shape with the description/date/... of the revision. I want to use this shape to hold the VBA code. A right click on that shape could then give you an action menu to choose between print or no print.
So in the Shapesheet I go, and add this to the action cell:
RUNMACRO("Page_Layout.Module1.RevisionPrint")
The master shape is added to the stencil, and the stencil is saved as a stencil containing a macro.

Unfortunatly, this pops up an unspecified VBA error  :(

I guess it has something to do with either not finding the macro in the stencil, or that the references to the pages and layers are looking at the stencil instead of the document.

Anybody that can point me in the right direction?

Thanks!

Paul Herber

Your code references ActiveDocument. This might not be the document you really want. You might need to be more specific about which document you are processing.
Electronic and Electrical engineering, business and software stencils for Visio -

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

Soundstorm

Quote from: Paul Herber on December 01, 2023, 12:13:53 PM
Your code references ActiveDocument. This might not be the document you really want. You might need to be more specific about which document you are processing.
Yes, that is indeed a reference that could be wrong.

But I add the shape to the document, and the document is active. So I would expect that link to be valid. But maybe it still references the stencil where the macro is located, as that is probably also active?

Soundstorm

Ok, the code doesn't seem to be the problem.

If I just place this in the sub, I get the same error.
MsgBox ("Hello world")

So it is probably related to some problem with access to the files? These are all on Onedrive.

Surrogate

Quote from: Soundstorm on December 01, 2023, 03:04:05 PM
These are all on Onedrive.
You can open these files at your local drive?

Paul Herber

Electronic and Electrical engineering, business and software stencils for Visio -

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