FREEZING A LIST OF LAYERS WITH VBA?
FREEZING A LIST OF LAYERS WITH VBA?
(OP)
I AM ATTEMPTING TO FREEZE A LIST OF LAYERS WITH A VBA MACRO. CAN I MODIFY THIS CODE TO FREEZE A LIST OF LAYERS BY NAME? I HAVE TRIED TO PUT A LAYER NAME IN (SHOWN IN RED) BUT IT DOES NOT WORK. I KNOW IT IS NOT THE CORRECT SYNTAX.
Dim FRZLayer As AcadLayer
For Each FRZLayer In ThisDrawing.Layers ("A-WALL")
FRZLayer.Freeze = True
Next FRZLayer
End Sub
Dim FRZLayer As AcadLayer
For Each FRZLayer In ThisDrawing.Layers ("A-WALL")
FRZLayer.Freeze = True
Next FRZLayer
End Sub
RE: FREEZING A LIST OF LAYERS WITH VBA?
Try this...
CODE
Dim FRZLayer as AcadLayer
For Each FRZLayer In ThisDrawing.Layers
If FRZLayer.Name = "A-WALL" Then
FRZLayer.Freeze = True
End IF
Next FRZLayer
or:
CODE
Dim strLyrs as Variant
Dim iCnt as Integer
strLyrs = Array("A-WALL", "A-GLAZ", "A-DOOR")
For iCnt = LBound(strLyrs) to UBound(strLyrs)
ThisDrawing.Layers(strLyrs(iCnt)).Freeze = True
Next iCnt
HTH
Todd
RE: FREEZING A LIST OF LAYERS WITH VBA?
RE: FREEZING A LIST OF LAYERS WITH VBA?
RE: FREEZING A LIST OF LAYERS WITH VBA?
For your first question, no, VBA will want a fully qualified name for this work, no wildcards allowed.
I just tried the code above (with the array) and it worked for me, you might check and see if one of the layers you are trying to freeze is the current layer, that may cause the routine to not work.
HTH
Todd
RE: FREEZING A LIST OF LAYERS WITH VBA?
RE: FREEZING A LIST OF LAYERS WITH VBA?
Function layfreeze(sLayers As String)
''sLayers is a string containing the layer(s) to be frozen, seperated by commas. _
May conatin wildcards..... "Layer1,ThisOne2,ANNO*"
Dim oLay As AcadLayer
Dim sLayName As Variant
Dim vLayers As Variant
vLayers = Split(sLayers, ",")
For Each oLay In ThisDrawing.Layers
For Each sLayName In vLayers
If (oLay.Name Like sLayName) And (ThisDrawing.ActiveLayer.Name <> oLay.Name) Then
oLay.Freeze = True
Exit For
End If
Next
Next oLay
End Function
Sub test()
layfreeze "*CONT*,C-*"
End Sub
RE: FREEZING A LIST OF LAYERS WITH VBA?
It should work fine, if you look, it's using the Like operator to make a wildcard type function - should do what you need.
HTH
Todd
RE: FREEZING A LIST OF LAYERS WITH VBA?
Sub test()
layfreeze ("*CONT*", "c-*")
End Sub
This still doesnt work. even with layers with names with cont etc in them.
RE: FREEZING A LIST OF LAYERS WITH VBA?
From the looks of the routine, you'll only be able to pass it one layer name at a time - something like:
CODE
HTH
Todd