谢谢你的代码。我使用你的代码并修复我的代码。但我仍然有错误。数组出现“类型不匹配”错误。
你能看一下吗?
这是我的密码
- Option Explicit
- Const xlFileName As String = "C:\Users\halil.abakay\Desktop\AutoCAD.xlsx" '<--change existing file name here
- Public Sub Text_to_Excel()
- Dim SS As AcadSelectionSet
- Dim ftype(0) As Integer
- Dim fdata(0) As Variant
- Dim obj As AcadObject
- Dim otext As AcadText
- Dim txtdata_km
- Dim txtdata_srbst
- Dim txtdata_dolgu
- Dim txtdata_yarma
- Dim counter1 As Long
- Dim counter2 As Long
- Dim counter3 As Long
- Dim counter4 As Long
- Dim counterveri As Integer
- Dim k As Integer
- Dim xcoord As Double
- Dim ycoord As Double
- Dim txtstring As String
- Dim xlApp As Object
- Dim xlBook As Workbook
- Dim xlSheet As Worksheet
- Dim lngRow As Long, lngCol As Long
- On Error Resume Next
- '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Set xlApp = GetObject(, "Excel.Application")
-
- If Err <> 0 Then
- Err.Clear
- Set xlApp = CreateObject("Excel.Application")
- If Err <> 0 Then
- MsgBox "Impossible to run Excel.", vbExclamation
- End
- End If
- End If
- xlApp.Visible = True
-
- Set xlBook = xlApp.Workbooks.Open(xlFileName)
-
- Set xlSheet = xlBook.Sheets(1)
-
- xlApp.ScreenUpdating = True
- If xlSheet.Range("A1") = "" Then
- lngRow = 1: lngCol = 1
- Else
- lngRow = xlSheet.Range("a65536").End(3).Offset(1, 0).Row: lngCol = 1
- End If
- '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ftype(0) = 0:
- fdata(0) = "TEXT":
- With ThisDrawing.SelectionSets
- While .Count > 0
- .Item(0).Delete
- Wend
- End With
-
- With ThisDrawing.SelectionSets
- Set SS = .Add("Textkubaj")
- End With
- SS.SelectOnScreen ftype, fdata
-
-
- If SS.Count = 0 Then
- MsgBox "Nothing selected"
- Exit Sub
- Else
- counter1 = 0
- counter2 = 0
- counter3 = 0
- counter4 = 0
- counterveri = 0
- For Each obj In SS
-
- Set otext = obj
-
- If InStr(1, otext.TextString, "Km =") > 0 Then
- counter1 = counter1 + 1
- ReDim Preserve txtdata_km(0 To 2, counter1 - 1)
- xcoord = otext.InsertionPoint(0)
- ycoord = otext.InsertionPoint(1)
- txtstring = otext.TextString
- txtdata_km(0, counter1 - 1) = xcoord: txtdata_km(1, counter1 - 1) = ycoord: txtdata_km(2, counter1 - 1) = txtstring
- counterveri = counterveri + 1
-
- ElseIf InStr(1, otext.TextString, "Serbest Kazı=") > 0 Then
- counter2 = counter2 + 1
- ReDim Preserve txtdata_srbst(0 To 2, 0 To counter2 - 1)
- xcoord = otext.InsertionPoint(0)
- ycoord = otext.InsertionPoint(1)
- txtstring = otext.TextString
- txtdata_srbst(0, counter2 - 1) = xcoord: txtdata_srbst(1, counter2 - 1) = ycoord: txtdata_srbst(2, counter2 - 1) = txtstring
- counterveri = counterveri + 1
-
- ElseIf InStr(1, otext.TextString, "Dolgu =") > 0 Then
- counter3 = counter3 + 1
- ReDim Preserve txtdata_dolgu(0 To 2, 0 To counter3 - 1)
- xcoord = otext.InsertionPoint(0)
- ycoord = otext.InsertionPoint(1)
- txtstring = otext.TextString
- txtdata_dolgu(0, counter3 - 1) = xcoord: txtdata_dolgu(1, counter3 - 1) = ycoord: txtdata_dolgu(2, counter3 - 1) = txtstring
- counterveri = counterveri + 1
-
- ElseIf InStr(1, otext.TextString, "Yarma =") > 0 Then
- counter4 = counter4 + 1
- ReDim Preserve txtdata_yarma(0 To 2, 0 To counter4 - 1)
- xcoord = otext.InsertionPoint(0)
- ycoord = otext.InsertionPoint(1)
- txtstring = otext.TextString
- txtdata_yarma(0, counter4 - 1) = xcoord: txtdata_yarma(1, counter4 - 1) = ycoord: txtdata_yarma(2, counter4 - 1) = txtstring
|