ToniPerez
Mechanical
- Mar 10, 2012
- 25
Dear all,
I would like to create a macro that will make the following steps
From a list of CATParts
1. Open a CATpart saved in a specific folder ( ex c:\Temp\input)
2. Retrieve info from catpart (part name)and export to excel
3. Go to step 1
3. Save excel sheet in a especific folder (ex c:\Temp\output)
The code i have just created finally is able to the excel sheet but is not able to export the properties of the catparts.
Any ideas how to fix this issue?
Many thanks and regards
Sub CATMain()
Dim documents1 As Documents
Set documents1 = CATIA.Documents
MsgBox “The number of documents is ” & documents1.Count
Dim doc1 As String
Set doc1 = documents1.Item(1)
‘MsgBox doc1.Name
‘MsgBox doc1.FullName
‘For Each doc1 in documents1
‘MsgBox doc1.Name
‘Next
Dim partDoc1 as PartDocument
Set partDoc1 = doc1
MsgBox partDoc1.Name
‘to excel
Dim Excel As Object
Dim workbooks As workbooks
Dim workbook As workbook
Dim worksheet As Excel.worksheet
On Error Resume Next
Set Excel = GetObject(, “EXCEL.Application”)
If Err.Number <> 0 Then
Err.Clear
Set Excel = CreateObject(“EXCEL.Application”)
Else
Err.Clear
MsgBox “Please note you have to close Excel”, vbCritical
Exit Sub
End If
Excel.Visible = True
‘load a sheet
Set workbooks = Excel.Application.workbooks
Set myworkbook = Excel.workbooks.Add
Set myworksheet = Excel.ActiveWorkbook.Add
Set myworksheet = Excel.Sheets.Add
‘download the properties
‘row one
Excel.Cells(1,1)=”Part Number”
‘row 2
Excel.Cells(2,1)= doc1
End Sub