0

I am writing a macro in CATIA v5 using VBA. The program is suppose to take points from a geometric set and transfer them into an excel file. I have successfully gotten the excel document open, a header created, but then I receive "Run-time error '438': Object doesn't support this property or method. I have tried searching around and it seems like the section of code is trying to interact with something outside of its domain, but I cannot figure out how. Below is a sample of my code. The line that contains "***" to the left is the line that is being pointed out in the debugger.

Dim xls As Object
Dim wkbks As Object
Dim wkbk As Object
Dim wksheets As Object
Dim sheet As Object
Dim fs, f, f1, fc, s
Dim coords(2) As Integer
Dim PartDoc

Sub CATMain()

    CATIA.ActiveDocument.Selection.Search "CATGmoSearch.Point,all"

    'Function Calls
    AppStart
    CATIAtoXLS

    'wksheet.Application.ActiveWorkbook.SaveAs (ExcelFolder & Left(CATIA.ActiveDocument.Name,Len(CATIA.ActiveDocument.Name)-8)&".xls")
    'wksheet.Application.ActiveWorkbook.Close

End Sub

Private Sub AppStart()

    Err.Clear
    On Error Resume Next
    Set xls = GetObject(, "Excel.Application")
    If Err.Number <> 0 Then
        Err.Clear
        Set xls = CreateObject("Excel.Application")
    End If

    xls.Application.Visible = True
    Set wkbks = xls.Application.Workbooks
    Set wkbk = wkbks.Add
    Set wksheets = wkbk.Worksheets(1)
    Set sheet = wkbk.Sheets(1)
    sheet.Cells(1, "A") = "X-Cord"
    sheet.Cells(1, "B") = "Y-Cord"
    sheet.Cells(1, "C") = "Z-Cord"

End Sub

Private Sub CATIAtoXLS()

    For i = 1 To CATIA.ActiveDocument.Selection.Count
        Set Selection = CATIA.ActiveDocument.Selection        ***
        Set Element = Selection.Item(i)

        'Transfer data to xls
        Point.GetCoordinates (coords)
        sheet.Cells(i + 1, "A") = coords(0)
        sheet.Cells(i + 1, "B") = coords(1)
        sheet.Cells(i + 1, "C") = coords(2)

    Next i

End Sub
Comintern
  • 21,855
  • 5
  • 33
  • 80
  • See [this thread](http://www.coe.org/p/fo/et/thread=14001) from their support forum. – Comintern Feb 11 '19 at 22:02
  • 2
    I don't know CATIA, but an object called `Selection` seems like a bad idea to me. Maybe give it a less ambiguous name - `OSel` perhaps? – CLR Feb 11 '19 at 22:03
  • @CLR I don't know CATIA either, but [from what appears to be the documentation](http://catiadoc.free.fr/online/interfaces/interface_Selection.htm), that's not a user defined variable. – Comintern Feb 11 '19 at 22:13
  • Well it seems changing the name actually fixed that error! Now on the line "Point.GetCoordinates (coords)" it says there is a type mismatch. I attempted declaring coords as a variant, but it did not change anything. EDIT: Got it working. I accidentally deleted a line i didn't mean to! – Trevor R. Shreve Feb 11 '19 at 22:25

1 Answers1

0

Your first issue is that in any method in CATIA VBA which passes an array as an argument, must be called on a object declared variant (explicitly or by default). So you it should look like this:

Dim px as Variant
Set px = CATIA.ActiveDocument.Selection.Item(i).Value
Call Point.GetCoordinates(coords)

The second problem is that in VBA if you use a subroutine with parentheses, you must use the Call keyword:

Call Point.GetCoordinates (coords)

Otherwise, you can skip the parentheses and the keyword:

Point.GetCoordinates coords
C R Johnson
  • 964
  • 1
  • 5
  • 12