×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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

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

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

CODE --> VBA

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

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

(OP)
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

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

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

Eric N.
indocti discant et ament meminisse periti

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

Hi,

Use selection1.Item(i).LeafProduct.PartNumber ....instead of selection1.Item(i).Value.PartNumber for example and see what is going on.

Where did you find SubAssembly ? There is no topic in v5automation.chm file regarding this (or at least I wasn't able to find it).

Regards
Fernando

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

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

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources