Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB program to export name, value, parent and current product to excel

Status
Not open for further replies.

L2S512

Aerospace
Nov 20, 2013
9
GB
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

 
Replies continue below

Recommended for you

replace the last lines with this and let us know if it works better

Code:
objGEXCELSh.Cells(i + 1, "A") = selection1.Item(i).Value.Name 'the parent name
objGEXCELSh.Cells(i + 1, "B") = selection1.Item(i).Value.Value 'the value of this parameter including unit
objGEXCELSh.Cells(i + 1, "C") = selection1.Item(i).Document.Name 'which CATProudcut is it below

Eric N.
indocti discant et ament meminisse periti
 
Hi
It still doesn't work. In the left bottom of window it counts the selection, and it will be no responding after something like 100.

I read my code a lot of times. Everything is ok but section of Sub ExportPoint()' looks like the reason why it doesn't work.

'******************************************************************************
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


Any idea of these code?

Many many many thanks

L
 
Can you run it step by step using F8 and see what is going on?

Eric N.
indocti discant et ament meminisse periti
 
Hi Ferdo

I am new to VBA, and what I can do now is get some similar code,go through it, find something I can use and learn in this process.

one more question.

I've made one and I can run it. sometimes CATIA will be no responding because a 'search' section in code. How can I make a variable to take the place of 'search'? My aims are all parameter named by 'radius'.

Many thanks
L
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top