Link to home
Start Free TrialLog in
Avatar of khott2003
khott2003

asked on

How can I add a selected shape to a layer from a combobox?

Hello,

I created a combo box that lists all of the existing layers on the active page.

I have been able to create a macro that will add selected shapes to a layer which is specified in the combo box.

I am trying to create a macro that will hide the layer that is selected in the combo box. I am receiving an error at this line:

Sub HideLayer
-> Set objLayer = objLayers(Layername)

I have a feeling that I should be using a different syntax since I need to use FormulaU to toggle the layer's visibility, but I don't know what it would be.

Any suggestions?

Thank you!!
Kyle


Private Sub ComboBox1_DropButtonClick()
Dim lngCurSel As Long
 
'Save Current selection
lngCurSel = ComboBox1.ListIndex
 
'Remove items or we will keep adding them over an over...
ComboBox1.Clear
 
 
'Loop Comboxbox1.additem ("Layer Name") for each layer
For i = 1 To ActivePage.Layers.Count
    
    Dim Layername
    Layername = ActivePage.Layers.Item(i).Name
    
    ComboBox1.AddItem Layername
    
Next
 
 
'Reset the selection
ComboBox1.ListIndex = lngCurSel
 
End Sub
 
 
 
Sub AddToLayer()
 
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Layer")
 
 
Dim objShps As Visio.Selection, objShp As Visio.Shape
Dim objLayers As Visio.Layers, objLayer As Visio.Layer
Dim i As Integer
 
'get the Selection
Set objShps = Visio.ActiveWindow.Selection
 
Dim Layername
Layername = ThisDocument.ComboBox1.Value
MsgBox Layername
 
'get the layers collection
Set objLayers = Visio.ActivePage.Layers
Set objLayer = objLayers(Layername)
 
For i = 1 To objShps.Count
Set objShp = objShps(i)
objLayer.Add objShp, 0
 
Next i
 
End Sub
 
 
 
 
 
 
 
Sub HideLayers()
 
    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope("Layer Properties")
    
    Dim Layername
    Layername = ThisDocument.ComboBox1.Value
    MsgBox Layername
    
 
    Set objLayers = Visio.ActivePage.Layers
    Set objLayer = objLayers(Layername)
    
    If objLayer.CellsC(visLayerVisible).FormulaU = "1" Then
    objLayer.CellsC(visLayerVisible).FormulaU = "0"
    Else
    objLayer1.CellsC(visLayerVisible).FormulaU = "1"
    End If
    
    Application.EndUndoScope UndoScopeID1, True
 
End Sub

Open in new window

SOLUTION
Avatar of Scott Helmers
Scott Helmers
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial