Hi everyone
I am going to make a macro which can export the name, value, parent and current product to excel.
This is my code. It will take one hour then no responding when I run it.
I am really new to CATIA VBA and just start to learn it.
Any body can go through my code and tell me anything I missed.
Many thanks
L
Dim objGEXCELapp As Object
Dim objGEXCELwkBks As Object
Dim objGEXCELwkBk As Object
Dim objGEXCELwkShs As Object
Dim objGEXCELSh As Object
Dim PartDocument1
Sub CATMain()
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Search "Name = Radius,all"
StartEXCEL
ExportPoint
End Sub
'******************************************************************************
Sub StartEXCEL()
'******************************************************************************
Err.Clear
On Error Resume Next
Set objGEXCELapp = GetObject(, "EXCEL.Application")
If Err.Number <> 0 Then
Err.Clear
Set objGEXCELapp = CreateObject("EXCEL.Application")
End If
objGEXCELapp.Application.Visible = True
Set objGEXCELwkBks = objGEXCELapp.Application.WorkBooks
Set objGEXCELwkBk = objGEXCELwkBks.Add
Set objGEXCELwkShs = objGEXCELwkBk.Worksheets(1)
Set objGEXCELSh = objGEXCELwkBk.Sheets(1)
objGEXCELSh.Cells(1, "A") = "Parent"
objGEXCELSh.Cells(1, "B") = "Size"
objGEXCELSh.Cells(1, "C") = "SubAssemly"
End Sub
'******************************************************************************
Sub ExportPoint()
'******************************************************************************
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Search "Name = Radius,all"
For i = 1 To selection1.Count
objGEXCELSh.Cells(i + 1, "A") = selection1.Item(i).Value.Parent.Name 'the parent name
objGEXCELSh.Cells(i + 1, "B") = selection1.Item(i).Value.PartNumber 'the value of this parameter including unit
objGEXCELSh.Cells(i + 1, "C") = selection1.SubAssemly 'which CATProudcut is it below
Next
End Sub
I am going to make a macro which can export the name, value, parent and current product to excel.
This is my code. It will take one hour then no responding when I run it.
I am really new to CATIA VBA and just start to learn it.
Any body can go through my code and tell me anything I missed.
Many thanks
L
Dim objGEXCELapp As Object
Dim objGEXCELwkBks As Object
Dim objGEXCELwkBk As Object
Dim objGEXCELwkShs As Object
Dim objGEXCELSh As Object
Dim PartDocument1
Sub CATMain()
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Search "Name = Radius,all"
StartEXCEL
ExportPoint
End Sub
'******************************************************************************
Sub StartEXCEL()
'******************************************************************************
Err.Clear
On Error Resume Next
Set objGEXCELapp = GetObject(, "EXCEL.Application")
If Err.Number <> 0 Then
Err.Clear
Set objGEXCELapp = CreateObject("EXCEL.Application")
End If
objGEXCELapp.Application.Visible = True
Set objGEXCELwkBks = objGEXCELapp.Application.WorkBooks
Set objGEXCELwkBk = objGEXCELwkBks.Add
Set objGEXCELwkShs = objGEXCELwkBk.Worksheets(1)
Set objGEXCELSh = objGEXCELwkBk.Sheets(1)
objGEXCELSh.Cells(1, "A") = "Parent"
objGEXCELSh.Cells(1, "B") = "Size"
objGEXCELSh.Cells(1, "C") = "SubAssemly"
End Sub
'******************************************************************************
Sub ExportPoint()
'******************************************************************************
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Search "Name = Radius,all"
For i = 1 To selection1.Count
objGEXCELSh.Cells(i + 1, "A") = selection1.Item(i).Value.Parent.Name 'the parent name
objGEXCELSh.Cells(i + 1, "B") = selection1.Item(i).Value.PartNumber 'the value of this parameter including unit
objGEXCELSh.Cells(i + 1, "C") = selection1.SubAssemly 'which CATProudcut is it below
Next
End Sub