Visio Discussions > ShapeSheet & Smart Shapes

Run a macro from a stencil

(1/2) > >>

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:

--- Code ---
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
--- End code ---

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:

--- Code ---
RUNMACRO("Page_Layout.Module1.RevisionPrint")
--- End code ---
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.

Soundstorm:

--- Quote from: Paul Herber on December 01, 2023, 07:13:53 AM ---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.

--- End quote ---
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.

--- Code ---
MsgBox ("Hello world")
--- End code ---

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, 10:04:05 AM ---These are all on Onedrive.

--- End quote ---
You can open these files at your local drive?

Navigation

[0] Message Index

[#] Next page

Go to full version