- UID
- 779793
- 积分
- 5
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2018-9-17
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Sub 读取到excel文字A()
Dim a As String
Dim objMText As AcadMText
Dim objTEXT As AcadText
Dim xlApp As Excel.Application
Dim xlSheet As Excel.Worksheet
Dim h As Integer
Dim hi As Integer
Dim ptPick As Variant
On Error Resume Next
ThisDrawing.Utility.GetEntity objMText, ptPick
a = GetTextUnformatString(objMText.TextString)
If Err.Number = "13" Then GoTo BB
BB:
ThisDrawing.Utility.GetEntity objTEXT, ptPick
a = GetTextUnformatString(objMText.TextString)
MsgBox GerTextUnformatString(objTEXT.TextSing)
objTEXT.Delete
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
MsgBox "Excel应用程序没有运行!"
Exit Sub
End If
Set xlSheet = xlApp.ActiveSheet
xlSheet.Cells(1, 5) = "=SUM(R[1]C:R[599]C,1)"
MsgBox GetMTextUnformatString(objMText.TextString)
objMText.Delete
aa:
h = xlSheet.Cells(1, 5).Value
hi = h + 1
xlSheet.Cells(hi, 2).Value = a
xlApp.Active
End Sub
Public Function GetMTextUnformatString(MTextString As String) As String
Dim s As String
Dim RE As Object
Set RE = ThisDrawing.Application.GetInterfaceObject("Vbscript.RegExp")
RE.IgnoreCase = True
RE.Global = True
s = MTextString
RE.Pattem = "\\\\"
s = RE.Replace(s, Chr(1))
RE.Pattem = "\\{"
s = RE.Replace(s, Chr(2))
RE.Pattem = "\\}"
s = RE.Replace(s, Chr(3))
RE.Pattem = "\\pi(.[^;]*);"
s = RE.Replace(s, "")
RE.Pattem = "\\pt(.[^;]*);"
s = RE.Replace(s, "")
RE.Pattem = "\\S(.[^;]*)(\^|#|\\)(.[^;]*);"
s = RE.Replace(s, "$1$3")
RE.Pattem = "(\\F|\\C|\\H|\\T|\\Q|\\W|\\A)(.[^;]*);"
s = RE.Replace(s, "")
RE.Pattem = "(\\L|\\O|\\l|\\o)"
s = RE.Replace(s, "")
RE.Pattem = "\\~"
s = RE.Replace(s, "")
RE.Pattem = "\\P"
s = RE.Replace(s, "")
RE.Pattem = vbLf
s = RE.Replace(s, "")
RE.Pattem = "({})"
s = RE.Replace(s, "")
RE.Pattem = "\x01"
s = RE.Replace(s, "\")
RE.Pattem = "\x02"
s = RE.Replace(s, "{")
RE.Pattem = "\x03"
s = RE.Replace(s, "}")
Set RE = Nothing
GetMTextUnformatString = s
End Function
Public Function GetTextUnformatString(TextString As String) As String
Dim s As String
Dim RE As Object
Set RE = ThisDrawing.Application.GetInterfaceObject("Vbscript.RegExp")
RE.IgnoreCase = True
RE.Global = True
s = TextString
RE.Pattem = "\\\\"
s = RE.Replace(s, Chr(1))
RE.Pattem = "\\{"
s = RE.Replace(s, Chr(2))
RE.Pattem = "\\}"
s = RE.Replace(s, Chr(3))
RE.Pattem = "\\pi(.[^;]*);"
s = RE.Replace(s, "")
RE.Pattem = "\\pt(.[^;]*);"
s = RE.Replace(s, "")
RE.Pattem = "\\S(.[^;]*)(\^|#|\\)(.[^;]*);"
s = RE.Replace(s, "$1$3")
RE.Pattem = "(\\F|\\C|\\H|\\T|\\Q|\\W|\\A)(.[^;]*);"
s = RE.Replace(s, "")
RE.Pattem = "(\\L|\\O|\\l|\\o)"
s = RE.Replace(s, "")
RE.Pattem = "\\~"
s = RE.Replace(s, "")
RE.Pattem = "\\P"
s = RE.Replace(s, "")
RE.Pattem = vbLf
s = RE.Replace(s, "")
RE.Pattem = "({})"
s = RE.Replace(s, "")
RE.Pattem = "\x01"
s = RE.Replace(s, "\")
RE.Pattem = "\x02"
s = RE.Replace(s, "{")
RE.Pattem = "\x03"
s = RE.Replace(s, "}")
Set RE = Nothing
GetTextUnformatString = s
End Function |
|