×
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

exApp As Excel.Application not defined

exApp As Excel.Application not defined

exApp As Excel.Application not defined

(OP)
I have a SolidWorks2010 model and want to export Keypoints to an Excel table. I used the following code, which I found in the FAQs, as a macro. However, I get the following error message whenever I try to compile: "User defined type not defined" (Not literally, I translated it from German to English). "exApp As Excel.Application" is highlighted.
Any suggestions?
Thanks

CODE

Sub main()
Dim swApp As SldWorks.SldWorks
Dim doc As SldWorks.ModelDoc2
Dim part As SldWorks.PartDoc
Dim sm As SldWorks.SelectionMgr
Dim feat As SldWorks.feature
Dim sketch As SldWorks.sketch
Dim v As Variant
Dim i As Long
Dim sseg As SldWorks.SketchSegment
Dim sline As SldWorks.SketchLine
Dim sp As SldWorks.SketchPoint
Dim ep As SldWorks.SketchPoint
Dim s As String

Dim exApp As Excel.Application
Dim sheet As Excel.Worksheet

 Set exApp = New Excel.Application
 If Not exApp Is Nothing Then
  exApp.Visible = True
  If Not exApp Is Nothing Then
   exApp.Workbooks.Add
   Set sheet = exApp.ActiveSheet
   If Not sheet Is Nothing Then
    sheet.Cells(1, 2).Value = "X"
    sheet.Cells(1, 3).Value = "Y"
    sheet.Cells(1, 4).Value = "Z"
   End If
  End If
 End If
 
 Set swApp = GetObject(, "sldworks.application")
 If Not swApp Is Nothing Then
  Set doc = swApp.ActiveDoc
  If Not doc Is Nothing Then
   If doc.GetType = swDocPART Then
    Set part = doc
    Set sm = doc.SelectionManager
    If Not part Is Nothing And Not sm Is Nothing Then
     If sm.GetSelectedObjectType2(1) = swSelSKETCHES Then
      Set feat = sm.GetSelectedObject4(1)
      Set sketch = feat.GetSpecificFeature
      If Not sketch Is Nothing Then
       v = sketch.GetSketchPoints
       For i = LBound(v) To UBound(v)
        Set sp = v(i)
        If Not sp Is Nothing And Not sheet Is Nothing And Not exApp Is Nothing Then
         'sheet.Cells(2 + i, 1).Value = "Normal Vector " & i + 1
         sheet.Cells(2 + i, 2).Value = Round(sp.x * 1000 / 25.4, DEC)
         sheet.Cells(2 + i, 3).Value = Round(sp.y * 1000 / 25.4, DEC)
         sheet.Cells(2 + i, 4).Value = Round(sp.z * 1000 / 25.4, DEC)
         exApp.Columns.AutoFit
        End If
       Next i
      End If
     End If
    End If
   End If
  End If
 End If
End Sub
 
 

RE: exApp As Excel.Application not defined

(OP)
I just ticked Microsoft Excel 10.0 Object Library and I dont get an error message anymore. However, the resulting excel table is blank except for "X,Y,Z".
Help please, its urgent.
Thanks so much

RE: exApp As Excel.Application not defined

Quote:

sheet.Cells(2 + i, 2).Value = Round(sp.x * 1000 / 25.4, DEC)

What is DEC?

Have you tried stepping through the code? Does this expression evaluate to a value?

Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
 

RE: exApp As Excel.Application not defined

(OP)
I dont have the slightest idea what DEC is. I have never worked with Visual Basic before and just copied the code from the FAQ to make a SolidWorks macro.

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