I'm trying to get the next layer to show when the user double clicks a shape.
I've never touched VBA within Visio so I tried the below code, I know its not much but I honestly do not have a clue unfortunately
Visio.layer.*Layername* visible = "1"
End Sub
Any help at all will be greatly appreciated.
what you mean as "Next layer" ?
In visio in Layer Properties Window layers are shown in order by name. In shapesheet layers are shown in order of creation !
VisioApp.ActivePage.Layers.Item("layername").CellsC(visLayerVisible).FormulaU = "1"
try this code
This can actually be done via simple shapesheet functions.
SetF(Getref(ThePage!=Layers.Visible[2]),true) - if you want to set Layer 2 to visible.
Switching from one layer to the next could be done be incrementing a counter on double-click + reset when max layers is reached.
=setf(getref(user.counter), if(user.counter>=user.MaxLayers, 1, user.counter+1)
Related
second question here, and I'll start with the obvious, I'm not a coder, just and enthusiastic ammateur! Thanks for your patience with my incorrect terminology etc!
I have a grid of Layers on a Visio document that I make visible/invisible using ToggleButtons. Imagine an 8 x 8 grid, with each square a box on it's own layer that becomes "highlighted" when the equivalent button is pressed. A-H, 1-8.
At the moment this means creating 64 individual subs:
Private Sub A4_Click()
Dim LyrNum As Integer
LyrNum = A4.Data1
If A4 Then
Call ToggleLayer3(LyrNum, 1)
A4.BackColor = RGB(243, 226, 160)
Else
Call ToggleLayer3(LyrNum, 0)
A4.BackColor = RGB(129, 133, 219)
Where the Data1 Property field contains the Layer Number for the grid reference.
I guess my first question is, is this really the best way of doing this? Seems a but clunky, but perhaps anything more elegant might be beyond me!
...
Second question, When horizontally adjacent layers are selected, I'd like to "mask" the join - essentially hide the lines between the boxes (they're a bit more complicated that straight squares). I have something that's starting to work, but again seems clunky and pretty labour intensive to set up.
I've made the Data2 Property Field the Layer numbers for the boxes to the left and right of the clicked layer (split by delimiter), and the Data3 Property Field the layer number for the "Masking". I can then split Data2 call a sub with (ClickedLayer, LayerBefore, LayerAfter, MaskingLayer, OnOff) and use If loops to see if the layer to the left is visible, and if so add the masking etc.
Means manually entering all the layer info into the property fields of each button etc, but works I guess.
I'm 100% sure there's a better way - I tried making the masking a object in the layer with a ShapeData of visible: True/False that could be changed from VBA, but that boggled my brain a bit. I guess I could have an Array of values in the VBA with the info I'm putting into Property Data# fields.
Thanks in advance for your help
Steve
i'am currently trying to add a small function to PowerPoint using VBA, my goal is to create a gadget that works kind of like Photoshop graphics layer.
My plan is to add a layer name Tag on each shape that is drawn by user, so later I can parse through every item by loop and preform lock/unlock, show/hide shapes based on it's tag value, such as:
Sub add_shape_with_layer_tag()
Set islide = ActivePresentation.Slides(1)
Set ishape = islide.Shapes.AddShape(msoShapeRectangle, 5, 5, 80, 60)
ishape.Tags.Add "Layer", "1"
End Sub
Sub show_hide_layer_one_shapes()
Dim active_slide As Slide
Set active_slide = ActiveWindow.View.Slide
For Each ishape In active_slide.Shapes
If ishape.Tags("Layer") = "1" Then
ishape.Visible = Not (ishape.Visible)
End If
Next ishape
End Sub
However, I couldn't found a way to achieve this, so I would like to ask whether there's a method that provides following functions?
override add shape function so I can sneak tag value in to shape every time user drawn a shape
catch add shape event (if this thing did exist) so i can add tag to the last added item
a way to set a default tag value to shape, just like setting default shape color/line width
or is there any better options that is also viable?
thanks.
20200728
To John, thanks for the advice, I did found some interesting event that might be helpful for some of my other projects, however I couldn't found events that able to trigger after custom function while shape is added.
To Steve, my plan is to add a modeless userform with list UI that manage layers, the shape tag and shape fill texture/color will be determined based on what list item that currently selected.
As to saving settings, I'll use VBComponents.CodeModule to dump existing settings in userforms to a VBA module and store as text, so in theory I should able to make this function self contained in one file.
Not totally an answer, sorry SO, but comments don't allow enough scope for this. So ...
To Steve, my plan is to add a modeless userform with list UI that manage layers, the shape tag and shape fill texture/color will be determined based on what list item that currently selected.
Ah, so you're creating your own "pseudo-layers". That wasn't clear. Thanks for the add'l info. As it happens, I have a selection manager add-in that works very similarly to what you're proposing.
To John, thanks for the advice, I did found some interesting event that might be helpful for some of my other projects, however I couldn't found events that able to trigger after custom function while shape is added.
The SelectionChange event should get you there. When it fires, you'll need to check first to see if the current selection is a shape or something else. If a shape, check to see if its .Index = current slide's .Shapes.Count and also to see if you've already tagged it. If no tag AND if it's the correct index, it'll be a newly added shape. If you're tagging ALL shapes, you may only need to check to see if the .Tag(name) is blank.
As to saving settings, I'll use VBComponents.CodeModule to dump existing settings in userforms to a VBA module and store as text, so in theory I should able to make this function self contained in one file.
Why not save any needed slide or presentation level info as further slide- or presentation-level tags? PPT can absorb quite a lot of info as tags w/o getting cranky.
I am new to VBA in PowerPoint and I am trying to develop an interactive program for my class where a text box grouped with a bubble shape floats across the screen and they have to click it if they notice it contains a certain grapheme. I want the clicked text boxes to copy to another slide so that I can assess if the children have been successful or just clicked anything they saw.
I've pieced together this code from other sites:
Sub copyobject()
With ActivePresentation
Set myshape1 = ActivePresentation.Slides(2).Shapes(group5)
myshape1.ActionSettings(ppMouseClick).Action = myshape1.Copy
.Slides(3).myshape1.Paste
End With
End Sub
It doesn't appear to be working though. Can anybody help me out?
The error message I receive is 'compile error: method or data member not found' with .myshape1 highlighted.
If anybody could give me a completed code for this or correct what I have created I would greatly appreciate it.
Many thanks
Since the name of the object is "group5", I assume it's a group. But you can't apply an Action Setting to a group, only to a single object. This works for a single shape:
Sub copyobject()
With ActivePresentation
Set myshape1 = .Slides(2).Shapes("Rectangle 1")
myshape1.ActionSettings(ppMouseClick).Action = myshape1.Copy
.Slides(3).Shapes.Paste
End With
End Sub
BTW, an excellent VBA book for what you're doing is David Markovitz's Powerful PowerPoint for Educators. His support site for the book also has lots of free code and samples.
I have a slide that we use in my department to provide an overview of the progress regarding project document deliverables. It is shown in a graphic manner, and therefore a simple table view or similar cannot be used. Each of the document deliverables mentioned on the slide can have 3 different legends (figures), a square, triangle and arrow. These are color coded according to stakeholder responsibility of the deliverable. Right now we are changing each one of them manually during the project
What I am looking for:
Is there a VBA code that can easily be used to replace these figures according to project status?
I imagine each Project deliverable needs to be tagged with a position on the slide, and then a userform can be used to select which type of figure there should be assigned?
Anyone who can help me or point me in a direction to something that might help me is highly appreciated!
Thank you
Peter
Here's one approach in rough outline ...
Instead of individual shapes, use a square, triangle and arrow grouped. The user selects the group they want to work with then launches your dialog box where they choose the project status for that item. Your dialog box assigns a value from 1 to 3 to the status then calls SetVisibility like so:
Sub MakeItSo()
Call SetVisibility(2)
End Sub
SetVisibility first makes all of the shapes in the group invisible, then sets the appropriate shape to be visible:
Sub SetVisibility(lStatus As Long)
Dim x As Long
With ActiveWindow.Selection.ShapeRange(1)
For x = 1 To .GroupItems.Count
.GroupItems(x).Visible = False
Next
.GroupItems(lStatus).Visible = True
End With
End Sub
Does anyone know how to ungroup SmartArt element via VBA?
Sub UngroupSmartArt()
Dim shapeWithSmartArt As Shape
Set shapeWithSmartArt = ActivePresentation.Slides(2).Shapes(2)
shapeWithSmartArt.Ungroup
End Sub
I get an error for this code:
"This member can only be accessed for a group."
It doesn't make any sense to me, because it's easily possible to do it in powerpoint itself (Right click on SmartArt -> Group -> Ungroup). It's driving me nuts :)
Can anyone help me with ungrouping SmartArt element/shape?
I also took a look on similar question, but it doesn't work properly, because ungrouped result is different in comparison to the one made via powerpoint itself.
Please help me out. I would really appreciate any help!
It is simply impossible to do it via VB code. That is also statement from Microsoft. Disadvantage of using SmartArt is also that user cannot record any actions with macro (using Excel) which are performed on this type of object/element.
It is also impossible to change width or height property of SmartArt nodes via VB, this was actually the reason why I wanted to change SmartArt element to shapes, because you can easily change width and height property of the shape via code.
Microsoft and their developers should really consider to make SmarArt element more developer-friendly, because I noticed I'm not the only one with these issues.
EDIT: Solution found! There is a way to execute commands from the powerpoint ribbon. You need to select your shape first, afterwards execute CommandBars.ExecuteMso with the action: SmartArtConvertToShapes.
Sub UngroupSmartArt()
Dim shapeWithSmartArt As Shape
Set shapeWithSmartArt = ActivePresentation.Slides(2).Shapes(2)
shapeWithSmartArt.Select
CommandBars.ExecuteMso("SmartArtConvertToShapes")
End Sub
This still doesn't change the fact and my point of view: Microsoft should really consider to make SmartArt element more friendly to developers!