×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

# Contact US

Log In

#### Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
To Your Posts
• Keyword Search
• One-Click Access To Your
Favorite Forums
• Automated Signatures
On Your Posts
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

# FREEZING A LIST OF LAYERS WITH VBA?

 Forum Search FAQs Links MVPs

## 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

### RE: FREEZING A LIST OF LAYERS WITH VBA?

Hi vbcad,

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?

(OP)
will this work with wildcard symbols? such as "*|A-WALL-glaz" in the list of layers? it doesn's seem to work properly for freezing xref layers.

### RE: FREEZING A LIST OF LAYERS WITH VBA?

(OP)
i have been experimenting further and the code examples above do not work for native as well as xref layers. they appear that they should work. i do not get an error but the drawing is not affected at all.

### RE: FREEZING A LIST OF LAYERS WITH VBA?

Hi vbcad,

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?

(OP)
you were right both work now. one of the layers was current. Is there a way to use wildcards with the VBA code? I have a lisp version of this which does accept wildcards. i am trying to use VBA to learn more of the functions.

### RE: FREEZING A LIST OF LAYERS WITH VBA?

(OP)
i found this on another forum. it claims to use wildcards but dont know if it works yet.

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?

Hi vbcad,

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?

(OP)
there seems to be a problem with the sub to call the routine. i tried quotes around the layer names.

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?

Hi vbcad,

From the looks of the routine, you'll only be able to pass it one layer name at a time - something like:

#### CODE

layfreeze "*CONT*"

HTH
Todd

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

### Reply To This Thread

#### Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!

Already a member? Close this window and log in.