-
- Private Sub SelectAllText(ByVal App As Object, objSset As Object, Optional ByVal strSsetname As String = "SELECTION~TEXT~1111")
- On Error GoTo err1
- Dim flag As Boolean
- flag = False
- For Each objSset In App.SelectionSets
- If objSset.Name = strSsetname Then
- flag = True
- Exit For
- End If
- Next
- If flag Then objSset.Delete '创建集合,如集存在,则删除,再新建
- Set objSset = App.SelectionSets.Add(strSsetname)
- Dim gpCode(0) As Integer
- Dim dataValue(0) As Variant
- gpCode(0) = 0
- dataValue(0) = "text,mtext"
- Dim groupCode As Variant, dataCode As Variant
- groupCode = gpCode
- dataCode = dataValue
- objSset.SelectOnScreen groupCode, dataCode
- Exit Sub
- err1:
- Debug.Print Err.Description
- Err.Clear
- End Sub
- Sub TT()
- Dim tstr As String, objSset As Object, objtrans As Object, reg As RegExp, objEntArr As New Collection, i As Integer, j As Integer
- Set Acdoc = AcadApplication.ActiveDocument
- SelectAllText Acdoc, objSset
- Set reg = CreateObject("Vbscript.RegExp")
- For i = 0 To objSset.Count - 1
- tstr = objSset.Item(i).TextString
- Debug.Print tstr
- reg.IgnoreCase = False
- reg.Global = True
- '替换\\字符
- reg.Pattern = "\\"
- tstr = reg.Replace(tstr, Chr(1))
- '替换\{字符
- reg.Pattern = "\\{"
- tstr = reg.Replace(tstr, Chr(2))
- '替换\}字符
- reg.Pattern = "\\}"
- tstr = reg.Replace(tstr, Chr(3))
- '删除段落缩进格式
- reg.Pattern = "\\pi(.[^;]*);"
- tstr = reg.Replace(tstr, "")
- '删除制表符格式
- reg.Pattern = "\\pt(.[^;]*);"
- tstr = reg.Replace(tstr, "")
- '删除堆迭格式
- reg.Pattern = "\\S(.[^;]*)(\^|#|\\)(.[^;]*);"
- tstr = reg.Replace(tstr, "")
- '删除字体、颜色、字高、字距、倾斜、字宽、对齐格式
- reg.Pattern = "(\\F|\\f|\\C|\\H|\\T|\\Q|\\W|\\A)(.[^;]*);"
- tstr = reg.Replace(tstr, "")
- '删除下划线、删除线格式
- reg.Pattern = "(\\L|\\O|\\l|\\o)"
- tstr = reg.Replace(tstr, "")
- '删除不间断空格格式
- reg.Pattern = "\\~"
- tstr = reg.Replace(tstr, "")
- '删除
- 符格式
- '.Pattern = "\\P"
- '.Replace tstr, "\r\n"
- '删除{}
- reg.Pattern = "({|})"
- tstr = reg.Replace(tstr, "")
- '替换回\\,\{,\}字符
- reg.Pattern = "\x01"
- tstr = reg.Replace(tstr, "")
- reg.Pattern = "\x01"
- tstr = reg.Replace(tstr, "{")
- reg.Pattern = "\x01"
- tstr = reg.Replace(tstr, "}")
- Next i
- Debug.Print tstr
- End Sub
|