[讨论][求助]vba利用鼠标获取text里面的数值。
<font face="Verdana"><font face="Verdana">各位达人,在VBA中如何利用鼠标获取text里面的数值?</font></font> <p>没人 回答 呀 </p><p> </p> <p>问题描述的太简单,没看懂</p> <p><font face="Verdana">终于搞出来了</font></p>
<p><font face="Verdana">贡献一下:</font></p>
<p><font face="Verdana"></font> </p>
<p><font face="Verdana">Public Function selectTextNum() As Double<br/> On Error Resume Next<br/> Dim ssetobj As AcadSelectionSet<br/> Dim strText As String, dblText As Double<br/> Dim blnHaveFoundText As Boolean, intCount As Integer<br/> ThisDrawing.SelectionSets("getTextNum").Delete<br/> Set ssetobj = ThisDrawing.SelectionSets.Add("getTextNum")<br/> ThisDrawing.Utility.Prompt "请选择<Text>格式的实体!"<br/> <br/> Dim pickedObjs As AcadEntity<br/> '循环每个被选择的实体<br/> blnHaveFoundText = False: intCount = 0<br/> Do<br/> ssetobj.SelectOnScreen<br/> If checkkey(escape) = True Then GoTo Finish:<br/> If Err Then Err.Clear<br/> If ssetobj.count = 0 Then<br/> If vbNo = MsgBox("没有选择实体,是否重新点选?", vbYesNo) Then selectTextNum = -1: Exit Function 'GoTo Finish '如果没有选择物体,结束程序<br/> Else<br/> For Each pickedObjs In ssetobj<br/> ' If TypeOf pickedObjs Is AcadPolyline Or TypeOf pickedObjs Is Acad3DPolyline Then<br/> ' Debug.Print pickedObjs.ObjectName<br/> ' If pickedObjs.ObjectName = "AcDbMText" Then<br/> ' pickedObjs.Highlight (True) ' = acRed '可将所有被选择实体将变为红色<br/> ' strText = pickedObjs.textString<br/> ' dblText = pickedObjs.Text<br/> ' selectTextNum = CDbl(strText) '得到每个实体对象的文本内容<br/> ' pickedObjs.Highlight (False) ' = acRed '可将所有被选择实体将变为红色<br/> ' End If<br/> If pickedObjs.ObjectName = "AcDbText" Then<br/> pickedObjs.Highlight (True) ' = acRed '可将所有被选择实体将变为红色<br/> strText = pickedObjs.textString<br/> selectTextNum = CDbl(strText) '得到每个实体对象的文本内容<br/> pickedObjs.Highlight (False) ' = acRed '可将所有被选择实体将变为红色<br/> ThisDrawing.Utility.Prompt "成功选取数值" & selectTextNum & ";" & vbCrLf<br/> blnHaveFoundText = True<br/> End If<br/> Next<br/> intCount = intCount + 1<br/> If False = blnHaveFoundText Then<br/> If intCount < 3 Then<br/> If vbNo = MsgBox("没有找到<Text>格式的实体,是否重新点选?", vbYesNo + vbQuestion) Then selectTextNum = -1: Exit Function<br/> Else<br/> MsgBox "没有找到<Text>格式的实体,尝试超过3次,请手动输入!", vbInformation + vbCritical<br/> selectTextNum = -1<br/> Exit Function<br/> End If<br/> End If<br/> End If<br/> Loop While (False = blnHaveFoundText And intCount < 3)<br/> ssetobj.Clear: ssetobj.Delete<br/> Exit Function<br/>Finish:<br/> ssetobj.Delete<br/> selectTextNum = -1<br/>End Function<br/></p></font> checkkey(escape)?
页:
[1]