VB。Net SelectFilter from Excel
尊敬的各位:,在Excel VBA中,我有一个宏,可以检索选定块的所有属性(选择也在Excel VBA中完成),并循环到Excel工作表中列出的所有文件。现在,我正在尝试将VBA迁移到VB。网
这里是我使用代码的地方,但它不起作用,我不知道为什么(当然,否则,我不会在这里;)
我正在使用Autocad 2013和Visual Studio 2010。
我试图选择C2单元中的块,
块位于单元格C1的布局上
在细胞C3层
我想宣言就是问题所在。。。。但我想不出。。。
PS:我不想使用NETLOAD命令,因为Autocad文件在操作过程中不应可见。
谢谢你的帮助。
赫维
Imports Microsoft.Office.Interop Imports System.Data.SqlClient Imports System.Data.OleDb Imports System.IO Imports Autodesk.AutoCAD.Interop Imports System Imports System.Runtime.InteropServices Imports Excel = Microsoft.Office.Interop.Excel Sub Import() xlsApp = New Excel.Application xlsApp.Visible = True xlsWB = xlsApp.Workbooks.Open(Frm_Main.LblFile1.Text) xlsSheetTwo = xlsWB.Worksheets("Import") Dim a As Integer a = 5 Dim dirInfo As New DirectoryInfo(Frm_Main.LblFolder1.Text) Dim fileInfo As FileInfo For Each fileInfo In dirInfo.GetFiles("*.dwg") 'dwg for Autocad xlsSheetTwo.Cells(a, 1) = fileInfo.Name a = a + 1 Next Dim AcadApp As AutoCAD.AcadApplication Dim SelSet As AutoCAD.AcadSelectionSet Dim Entity As AutoCAD.AcadEntity Dim BlocRef As AutoCAD.AcadBlockReference Dim filterType As Object Dim filterData As Object Dim p1(0 To 2) As Double Dim p2(0 To 2) As Double Dim grpCode(0 To 2) As Integer Dim grpValue(0 To 2) As String Dim i, Row, j, Column As Integer Dim Attributes As Object Dim ColumnExist As Boolean xlsSheetTwo.Select() ' Delete Excel records xlsSheetTwo.Range("B5:TZ65536").ClearContents() xlsApp.Application.Visible = True ' AutoCAD Connection On Error Resume Next AcadApp = GetObject(, "AutoCAD.Application") On Error GoTo 0 If AcadApp Is Nothing Then AcadApp = New AutoCAD.AcadApplication End If AcadApp.Visible = True 'Open the DWG Dim Opened As Boolean Opened = False Dim k As Integer k = 5 Row = 5 For k = 5 To xlsSheetTwo.Range("A65536").End(Excel.XlDirection.xlUp).Row AcadApp.Documents.Open(Frm_Main.LblFolder1.Text & "\" & xlsSheetTwo.Cells(k, 1).Text) On Error Resume Next SelSet = AcadApp.ActiveDocument.SelectionSets.Add("SELSET") If ErrorToString() <> 0 Then SelSet = AcadApp.ActiveDocument.SelectionSets.Item("SELSET") SelSet.Clear() End If 'Creation of Filter grpCode(0) = 8 ' Layer grpCode(1) = 2 ' Block Name grpCode(2) = 410 ' Layout filtertype = grpCode ' Filter on Layout Name grpValue(2) = xlsSheetTwo.Cells(1, 3).text ' Filter on BLOCK Name grpValue(1) = xlsSheetTwo.Cells(2, 3).text ' Filter on LAYER Name grpValue(0) = xlsSheetTwo.Cells(3, 3).text filterData = grpValue SelSet.Select(AutoCAD.AcSelect.acSelectionSetAll, , , filterType, filterData) ' Go throuhg Selection For i = 0 To SelSet.Count - 1 Entity = SelSet.Item(i) If Entity.ObjectName = "AcDbBlockReference" Then BlocRef = Entity If BlocRef.HasAttributes Then Attributes = BlocRef.GetAttributes For j = LBound(Attributes) To UBound(Attributes) Column = 3 ColumnExist = False While Not String.IsNullOrEmpty(xlsSheetTwo.Cells(4, Column)) If xlsSheetTwo.Cells(4, Column).Text = Attributes(j).TagString Then xlsSheetTwo.Cells(Row, Column).Value = Attributes(j).TextString ColumnExist = True End If Column = Column + 1 ' On passe à la colonne suivante End While If Not ColumnExist Then xlsSheetTwo.Cells(4, Column).Value = Attributes(j).TagString xlsSheetTwo.Cells(Row, Column).Value = Attributes(j).TextString End If Next ' Next Attribut End If End If Next AcadApp.ActiveDocument.Close() Row = Row + 1 'Next Line Next k AcadApp.Quit() MsgBox("Attributs of " & xlsSheetTwo.Cells(2, 1).Text & " have been retreived.") End Sub End Module
我没有(希望永远不会)使用。NET,所以我只能从VBA中猜测:filterType和filterData是否应该声明为变量(而不是对象)变量? 请看我的回答
http://forums.autodesk.com/t5/NET/VB...4652267#M37871
页:
[1]