RUNMACRO CALLTHIS ETC

Started by DAVEDEWEY, September 17, 2016, 08:18:29 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DAVEDEWEY

Morning all thanks for any advise in advance,,,

I have about 25-30 macros in a document that on the operation of a button will do one or a combination of the macros

Ive searched the net and tried RUNMACRO and CALLTHIS is various forms but just cant seem to get away from the error screen for example one of my macros is called EBCB1ON



DAVEDEWEY

Lots of good info, i think what im seeing is that the call this and runmacro are inside a stencil

they do not seem to work if place in document

DAVEDEWEY

There does not seem to be an easy to either run a macro as command rather than copy and paste or just make a layer change

I have a layer named EBHV that I just want to change its colour at the flick of a button ,,,,, "Any help before the cider kicks in"""

Yacine

Hi Dave,
Macros are often stored in stencils, so they can be loaded by any drawing as long as the stencil is open in them.
If you store the macro in the document - which is the same procedure as for the stencil - then the macro is only available in that one drawing.
Read carefully the callthis or the runmacro help and you should be able to implement your macro call.

Otherwise, you may think of uploading your file and let the guys have a look at your construction.
Rgds,
Y.
Yacine

DAVEDEWEY

Ok that makes sense so yesterday tried add a macro to the stencil which seemed ok

event run addon dble click but then this error appears

Sub EBON()

    'Enable diagram services
    Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140

    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope("Layer Properties")
    Dim vsoLayer1 As Visio.Layer
    Set vsoLayer1 = Application.ActiveWindow.Page.Layers.Item(9)
    vsoLayer1.CellsC(visLayerColor).FormulaU = "2"
    Application.EndUndoScope UndoScopeID1, True

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices

End Sub
Sub EBOFF()

    'Enable diagram services
    Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140

    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope("Layer Properties")
    Dim vsoLayer1 As Visio.Layer
    Set vsoLayer1 = Application.ActiveWindow.Page.Layers.Item(9)
    vsoLayer1.CellsC(visLayerColor).FormulaU = "4"
    Application.EndUndoScope UndoScopeID1, True

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices

End Sub

Yacine

2 things:
1) The error is not so much visio specific. It's a regular debugging task.
When your code stops at a specific line, inspect its elements. In your case check what "Application.ActiveWindow.Page.Layers" is. Does the object exist. Are there 9 items? etc.
May be you're in the wrong window, on the wrong page ???
2) When you re-use recorded code, you need to make it generic.
There was a topic with a similar question here: http://visguy.com/vgforum/index.php?topic=5802.0;nowap
Yacine