Results 1 to 3 of 3

Thread: AU 2005 VBA with Excel Sample Code

  1. #1
    100 Club wpeacock's Avatar
    Join Date
    2015-09
    Location
    Bunbury, West Australia
    Posts
    161
    Login to Give a bone
    0

    Cool AU 2005 VBA with Excel Sample Code

    In the process of working through this AU handout, on Integration of AutoCAD VBA with MS Excel by Dave Espinosa, I've come across an error message in this code when I've tried to run it.

    Error Massage: Object doesn't support this property or method. at'

    If ent.EntityType = acBlockReference And ent.Name = bnam Then btot = btot + 1

    1 - Any ideas on why it is doing this?
    2 - What is needed to fix it?

    Thanks

    Wayne
    Note: form requires three comand buttons and the list boxes.


    Code:
    Public excelApp As Object
    Public wkbObj As Object
    Public shtObj As Object
    Sub CommandButton1_Click()
    Dim i, j, btot As Integer
    Dim bnam As String
    Dim ent As Object
    btot = ThisDrawing.Blocks.Count
    For i = 0 To btot - 1
    bnam = ThisDrawing.Blocks.Item(i).Name
    If Not Mid$(bnam, 1, 1) = "*" Then ListBox1.AddItem bnam
    Next i
    For i = 0 To ListBox1.ListCount - 1
    bnam = ListBox1.List(i): btot = 0
    For j = 0 To ThisDrawing.ModelSpace.Count - 1
    Set ent = ThisDrawing.ModelSpace.Item(j)
    If ent.EntityType = acBlockReference And ent.Name = bnam Then btot = btot + 1
    Next j
    ListBox2.AddItem btot
    Next i
    End Sub
    Sub CommandButton2_Click()
    On Error Resume Next
    Set excelApp = GetObject(, "Excel.Application")
    If Err <> 0 Then
    Err.Clear
    Set excelApp = CreateObject("Excel.Application")
    If Err <> 0 Then
    MsgBox "Could not start Excel!", vbExclamation
    End
    End If
    End If
    excelApp.Visible = True
    Set wbkObj = excelApp.Workbooks.Add
    Set shtObj = wbkObj.Worksheets(1)
    shtObj.Name = "Block Count"
    Dim i, j, btot As Integer
    Dim bnam As String
    j = 1
    For i = 0 To ListBox1.ListCount - 1
    bnam = ListBox1.List(i)
    btot = ListBox2.List(i)
    shtObj.Cells(j, 1).Value = bnam
    shtObj.Cells(j, 2).Value = btot
    j = j + 1
    Next i
    End Sub
    Sub CommandButton3_Click()
    End ‘or ExcelApp.Quit Unload Me
    End Su

  2. #2
    100 Club wpeacock's Avatar
    Join Date
    2015-09
    Location
    Bunbury, West Australia
    Posts
    161
    Login to Give a bone
    0

    Default Re: AU 2005 VBA with Excel Sample Code

    Frustrated, I exploded the title block and it now works?

    Very confusing....

  3. #3
    All AUGI, all the time zoomharis's Avatar
    Join Date
    2005-02
    Location
    Abu Dhabi (Native-India)
    Posts
    506
    Login to Give a bone
    0

    Default Re: AU 2005 VBA with Excel Sample Code

    Quote Originally Posted by wpeacock
    If ent.EntityType = acBlockReference And ent.Name = bnam Then btot = btot + 1
    Not all Acad entities have 'Name' property. So testing for the entity name with those entities will generate an error. Try the following code to avoid this.

    Code:
      
    If ent.EntityType = acBlockReference Then
    	If ent.Name = bnam Then btot = btot + 1
    End If
    This code will first check whether the object type is AcadBlockReference ( which supports the Name property), then check for its name.

Similar Threads

  1. Error in a sample code ?
    By Dubweisertm in forum Dot Net API
    Replies: 3
    Last Post: 2011-09-08, 08:17 PM
  2. Sample code Error
    By r.vetrano in forum Revit - API
    Replies: 2
    Last Post: 2007-07-09, 11:42 AM
  3. Replies: 0
    Last Post: 2006-04-10, 05:38 PM
  4. Replies: 13
    Last Post: 2004-07-29, 11:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •