Solidworks Macro to Excel VBA

tbirdcarl

New Member
Joined
Jul 12, 2011
Messages
13
I am trying to create an assembly by inserting different drawings depending on the dimensions plugged into excel.

The Logic is solid in terms of when to add the different parts. My problem now is I don't know the code to insert the parts into the assembly.

I have tried the "record marco" and used that in the Excel VBA to no avail thus far.

an example of my efforts ( it continues on for quite a bit but this is the only bit of solidworks macro I have thus far):

Code:
Private Sub CommandButton1_Click()
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc

Dim Bot_message As Integer
Dim myForm As doorMsgBox2
Set myForm = New doorMsgBox2


Dim Hinge As Hinge_Orientation2
Set Hinge = New Hinge_Orientation2
Dim Height As Integer
Dim Width As Integer
Dim Depth As Integer

Dim Curb As String


W = Range("C2").Value
H = Range("C3").Value
D = Range("C4").Value

If W > 120 Or W < 14 Then
Range("D1") = "Invalid Width"
ElseIf H > 71.5 Or H < 14 Then
Range("D1") = "Invalid Height"
ElseIf D > 32 Or D < 12 Then
Range("D1") = "Invalid Depth"
Else


Curb = blank
'*** Vertical hinge or Horizontal hinge

Hinge.Caption = "Hinge Orientation"
Hinge.Show
Select Case Hinge.Tag
Case 1


    '***deciding if the cabinet has a bottom or not
    Bot_message = MsgBox("Does the Cabinet have a bottom?", vbYesNoCancel, "Cabinet Bottom inquiry")
    If Bot_message = 6 Then
    
    
        If H > W And W + D + D + 8.185 <= 144 And H < 60 Then
        ' ***insert the solidworks code for bottom (i.e.insert bottom part)(big piece will be horizontal)
        Part.AddComponent("Y:\N\sldwrks\macro\horizontal box\Horizontal_long.SLDPRT", 0, 0, 0)
        ElseIf H > W Then

Any help will be very much appreciated. I won't be able to re-test it till Monday .

Thanks
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top