Sometimes you need to assign lots of objects to different layers. Unfortunately, Visio's Layers dialog box is unwieldy and requires lots of clicks to get there. Here's a few macros that you can assign to keyboard shortcuts to help with that process.
To assign a keyboard shortcut, you have to add this macro to the file you're working on, and then click Developer > Macros > choose the macro > Options... and then assign a letter to it. Unfortunately Visio doesn't allow you to assign shortcuts to macros that aren't in that particular drawing, nor does it allow you to assign it to the Quick Access Toolbar.
Sub ToggleLayer()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Layer Properties")
Dim vsoLayer1 As Visio.Layer
Set vsoLayer1 = Application.ActiveWindow.Page.Layers.Item("main")
If vsoLayer1.CellsC(visLayerVisible).FormulaU = "0" Then
vsoLayer1.CellsC(visLayerVisible).FormulaU = "1"
Else
vsoLayer1.CellsC(visLayerVisible).FormulaU = "0"
End If
Application.EndUndoScope UndoScopeID1, True
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
Sub ShowAllLayers()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Layer Properties")
Dim vsoLayer1 As Visio.Layer
Set vsoLayer1 = Application.ActiveWindow.Page.Layers.Item("main")
vsoLayer1.CellsC(visLayerVisible).FormulaU = "1"
Application.EndUndoScope UndoScopeID1, True
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
Sub AssignToLayer()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Layer")
Set mylayer = Application.ActiveWindow.Page.Layers.Item("NAMEOFLAYER")
For i = 1 To Application.ActiveWindow.Selection.Count
mylayer.Add Application.ActiveWindow.Selection(i), 1
Next i
Application.EndUndoScope UndoScopeID1, True
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
Sub UnassignFromLayer()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Layer")
Set mylayer = Application.ActiveWindow.Page.Layers.Item("NAMEOFLAYER")
For i = 1 To Application.ActiveWindow.Selection.Count
mylayer.Remove Application.ActiveWindow.Selection(i), 1
Next i
Application.EndUndoScope UndoScopeID1, True
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub