To list the layers and hide the "foo" layer if it exists:
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swLayerMgr As SldWorks.LayerMgr
Dim vLayerArr As Variant
Dim vLayer As Variant
Dim swLayer As SldWorks.Layer
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swLayerMgr = swModel.GetLayerManager
vLayerArr = swLayerMgr.GetLayerList
For Each vLayer In vLayerArr
Set swLayer = swLayerMgr.GetLayer(vLayer)
If swLayer.Name = "toto" Then
swLayer.Visible = False
End If
Next
End Sub