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!

Catia to Excel File by Macro (Failure)

Status
Not open for further replies.

suleymanyaman

Industrial
Jul 30, 2013
29
Hi Dear Friends,


I create a catia macro for "product" and I want to export from catia to excel. However it gives failure in Dim workbooks As workbooks Dim workbook As workbook compile failure is"User-defined type not defined" codes in below.Thank you.

Sub MatrixPrint(ByVal sName, ByVal matrix)

Dim subString As String
Dim Excel As Object
Dim workbooks As workbooks
Dim workbook As workbook
Dim Sheets As Object
Dim Sheet As Object
Dim worksheet As Excel.worksheet
Dim myworkbook As Excel.workbook
Dim myworksheet As Excel.worksheet
Set workbooks = Excel.Application.workbooks
Set myworkbook = Excel.workbooks.Add
Set myworksheet = Excel.ActiveWorkbook.Add
Set myworksheet = Excel.Sheets.Add

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
Dim a(11)
Dim i As Integer
For i = 0 To 11
If ((matrix(i) < 0.001) And (matrix(i) > -0.001)) Then
a(i) = 0#
Else
a(i) = matrix(i)
End If
Next

sTemp = sName + " = " + CStr(a(9)) + ", " + CStr(a(10)) + ", " + CStr(a(11))

'count = 0

count = count + 1

subString = Right(sName, 4)
If subString = "IF.1" Then
MsgBox sName
Excel.Cells(2, count) = sName
Excel.Cells(2, count + 1) = CStr(a(9))
Excel.Cells(2, count + 2) = CStr(a(10))
Excel.Cells(2, count + 3) = CStr(a(11))
If strsearch = sName Then
sTemp = sName + " = " + CStr(a(9)) + ", " + CStr(a(10)) + ", " + CStr(a(11))

Excel.Cells(1, 1) = sName
Excel.Cells(1, 2) = CStr(a(9))
Excel.Cells(1, 3) = CStr(a(10))
Excel.Cells(1, 4) = CStr(a(11))

MsgBox sTemp
End If
End If
End Sub
 
Replies continue below

Recommended for you

I solve this question myself.I guess I am wrong while defined excel documentation."Dim workbooks As Workbooks" is changed "Dim workbooks" then solved it.
Thank you.
 
In VBA, Open Tools / References and make sure you have Microsoft Excel xx Object Library selected:

xx depends on your excel version, for Excel 2010, I have 14.0

download.aspx



Eric N.
indocti discant et ament meminisse periti
 
I understood clearly but I am working on .Catvba is it same?Because I saw your Location: c:\program Files(x86)\Microsoft Office\office14\EXCEL.EXE
 
Hi,

Eric is right, in catvba you have to set a reference to Excel (or any other program if you are using specific dll's coming with that program), doesn't matter where is installed.....

But take care because this can be an issue for other computers which doesn't have those dll's (references)....

Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor