[求助]请问我的程序错在哪里
<p>Public Sub 导出文字()</p><p> Dim Excel As Excel.Application</p><p> Dim ExcelSheet As Object</p><p> Dim ExcelWorkbook As Object</p><p> <br/> Dim LJ As String<br/> Dim NA As String<br/> <br/> Dim RowNum As Integer</p><p> Dim Header As Boolean</p><p> Dim elem As AcadEntity</p><p> Dim Arr() As String</p><p> Dim i As Integer<br/> <br/> '定义选择集和选择集元素<br/> Dim ssText As AcadSelectionSet<br/> Dim objSelected As AcadEntity<br/> <br/> '安全地创建选择集<br/> On Error Resume Next<br/> If Not IsNull(ThisDrawing.SelectionSets) Then<br/> Set ssText = ThisDrawing.SelectionSets<br/> ssText.Delete '及时删除不用的选择集非常重要<br/> End If<br/> Set ssText = ThisDrawing.SelectionSets.Add("Text")</p><p><br/> ' 获取本cad的路径和名字<br/> LJ = ThisDrawing.Path<br/> NA = ThisDrawing.Name<br/> <br/> ' 启动 Excel。<br/> Set Excel = New Excel.Application</p><p> </p><p> ' 创建新的工作簿并查找活动电子表格。</p><p> Set ExcelWorkbook = Excel.Workbooks.Add</p><p> Set ExcelSheet = Excel.ActiveSheet<br/> <br/> ExcelWorkbook.SaveAs LJ & "\" & Left(NA, Len(NA) - 4) & ".xls"<br/> <br/> <br/> </p><p> '提示用户在屏幕上选择文字<br/> 'MsgBox "请选择您想要导出的表格,然后按回车键", vbInformation, "提示"<br/> ThisDrawing.Utility.Prompt vbCr & "请选择您想要导出的表格,然后按回车键"<br/> <br/> <br/> '选择选择集,限定选择条件<br/> ssText.SelectOnScreen<br/> <br/> ' If ssText.Count = 0 Then Exit Sub<br/> <br/> <br/> <br/> '把块炸开<br/> For Each objSelected In ssText<br/> <br/> If LCase(objSelected.ObjectName) = "acdbblockreference" Then<br/> objSelected.Explode<br/> End If<br/> Next<br/> <br/> <br/> <br/> ' 循环选择的文字框内容<br/> i = 0<br/> For Each objSelected In ssText<br/> <br/> If LCase(objSelected.ObjectName) = "acadtext" Or LCase(objSelected.ObjectName) = "acadMtext" Then<br/> Arr(i) = objSelected.TextString<br/> i = i + 1<br/> End If<br/> <br/> Next<br/> <br/> <br/> ExcelWorkbook.Worksheets("sheet1").Active<br/> <br/> For i = 0 To UBound(Arr)<br/> ExcelWorkbook.Worksheets("sheet1").Cells(i + 1, 1) = Arr(i)<br/> Next<br/> <br/> <br/> <br/> <br/> <br/> ThisDrawing.SelectionSets.Item("Text").Delete<br/> <br/> Excel.Application.Quit<br/> ThisDrawing.Application.Update<br/>End Sub</p><p><font color="#ff0000">这是我写的一个导出cad文字到excel第一列的代码 我是参照着几个写的 </font></p><p><font color="#ff0000">为什么保存的excel里没有数据哦。。。呜呜呜呜 大家帮帮忙</font></p><font color="#ff0000"></font> <p>大家帮帮忙啊</p><p>谢谢各位大侠了~~~~~~</p> 用调试模式看看哪里出错了,我都是写在正在运行的Excel文件中,还没有直接保存过 <p>选中的如果是块就炸开,,是指内容为文字的块?但是你炸开他也不在你现在的选择集中啊。。</p><p>再有,判断完是文字类型后,也没有看你有把ARR数组的维数重新定义什么啊,直接是赋不上的呀,所以再怎么导出是空的</p><p>另外以上解决完后,我想你导出的文字应该也是乱序的</p>
页:
[1]