请教一段VBA代码
<p>Sub Getusersselection()<br/>Dim usersselection As AcadSelectionSet<br/>Dim drawingselected As AcadEntity<br/>With ThisDrawing<br/>On Error Resume Next<br/>.SelectionSets("currentselection").Delete<br/>MsgBox "select objects !hit enter to finish!"<br/><strong><em><u><font color="#ff0000">Set usersselection = ?</font><br/></u></em></strong>.SelectionSets.Add ("currentselection")<br/>usersselection.SelectOnScreen<br/>For Each drawingselected In usersselection<br/>drawingselected.color = acGreen<br/>Next<br/>End With<br/>End Sub</p><p>各位高手!小弟在此请教,该段代码的作用是在CAD模型空间选取直线进行变换颜色.</p><p>但代码中红色部分编译程序报错,我个人觉得也不符合格式,请问各位高手该段代码应该怎样修改.</p> <p>以下代码经过我测试,应该没问题的<br/>Sub Getusersselection()<br/>Dim usersselection As AcadSelectionSet<br/>Dim drawingselected As AcadEntity<br/>If ThisDrawing.SelectionSets.Count <> 0 Then<br/> Do While ThisDrawing.SelectionSets.Count <> 0<br/> ThisDrawing.SelectionSets.Item(0).Delete<br/> Loop<br/>End If<br/>MsgBox "select objects !hit enter to finish!"<br/>Set usersselection = ThisDrawing.SelectionSets.Add("example")<br/>usersselection.SelectOnScreen<br/>For Each drawingselected In usersselection<br/> drawingselected.color = acGreen<br/>Next<br/>usersselection.Delete<br/>End Sub<br/></p> 谢谢大哥!小弟还有一个问题。大哥是否看过AUTOCADVBA从入门到精通这本书。在第150页的第13行命令,大哥是否能将代码发送上来,小弟用的是扫描书,看不请里面的标点。 另大哥可否将QQ号等联系方式留给小弟,小弟初学有很多问题不懂,需请教! <p>楼主代码输入有误,红色代码和它下面一行应为同一行:</p><p><strong><em><u><font color="#ff0000">Set usersselection = </font></u></em></strong>.SelectionSets.Add ("currentselection")</p><p>二楼的这段代码:</p><p>If ThisDrawing.SelectionSets.Count <> 0 Then<br/> Do While ThisDrawing.SelectionSets.Count <> 0<br/> ThisDrawing.SelectionSets.Item(0).Delete<br/> Loop<br/>End If</p><p><br/>改为这样是不是更简单些?</p><p><br/>Do Until ThisDrawing.SelectionSets.Count = 0<br/> ThisDrawing.SelectionSets.Item(0).Delete<br/>Loop</p>
页:
[1]