+ Reply to Thread
Results 1 to 2 of 2

Polyline & Polygon Area

Hybrid View

  1. #1
    Registered User
    Join Date
    11-26-2019
    Location
    Thane
    MS-Off Ver
    2021
    Posts
    49

    Polyline & Polygon Area

    Dear Experts,

    I have tried the attached Code But when I run "Run-time error "-2145320851" show

    I Need your help on this subject

    Sub ExtractPolygonAreas()
    
    Dim acadApp As Object
    Dim acadDoc As Object
    Dim acadSelSet As Object
    Dim acadPoly As Object
    
    Set acadApp = GetObject(, "AutoCAD.Application")
    Set acadDoc = acadApp.ActiveDocument
    
    Set acadSelSet = acadDoc.SelectionSets.Add("polygons")
    acadSelSet.SelectOnScreen
    
    Dim i As Integer
    Dim j As Integer
    Dim area As Double
    Dim pointArray() As Double
    
    Dim xlApp As Object
    Dim xlWb As Object
    Dim xlWs As Object
    
    Set xlApp = CreateObject("Excel.Application")
    Set xlWb = xlApp.Workbooks.Add
    Set xlWs = xlWb.Sheets("Sheet1")
    
    xlWs.Cells(1, 1).Value = "Layer"
    xlWs.Cells(1, 2).Value = "Coordinates"
    xlWs.Cells(1, 3).Value = "Area"
    
    For i = 0 To acadSelSet.Count - 1
        Set acadPoly = acadSelSet.Item(i)
        area = acadPoly.area
        pointArray = acadPoly.Coordinates
        xlWs.Cells(i + 2, 1).Value = acadPoly.Layer
        xlWs.Cells(i + 2, 2).Value = "("
        For j = 0 To UBound(pointArray) - 1 Step 2
            xlWs.Cells(i + 2, 2).Value = xlWs.Cells(i + 2, 2).Value & "(" & pointArray(j) & "," & pointArray(j + 1) & ")"
        Next j
        xlWs.Cells(i + 2, 2).Value = xlWs.Cells(i + 2, 2).Value & ")"
        xlWs.Cells(i + 2, 3).Value = area
    Next i
    
    xlApp.Visible = True
    xlWb.SaveAs "PolygonAreas.xlsx"
    
    End Sub
    Last edited by rajatds31; 02-13-2023 at 09:01 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,890

    Re: Polyline & Polygon Area

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code] [/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Frequency Polygon
    By mermel in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 02-18-2021, 08:38 AM
  2. Error 1004 Program for area of irregular polygon
    By tzgajner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-22-2020, 11:59 AM
  3. Hypothetical Polygon
    By chrisellis250 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-18-2020, 10:05 AM
  4. Area of closed polygon (from Autocad to Excel)
    By rajatds31 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-18-2020, 09:15 AM
  5. Select polyline and bring area back to excel
    By rajatds31 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-24-2019, 01:49 AM
  6. How to draw Irregular Polygon
    By gaului in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2017, 11:19 AM
  7. [SOLVED] Formula to label the points of a polygon.
    By stockgoblin42 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-17-2013, 08:51 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1