Hi, I am new to programming and am trying to learn as much as I can. I was somehow able to make a macro, but I am trying to add a simple user form and I am having trouble determining what code to use and where to use it. My form just has 1 combo box and 1 command button. I would like the combo box to contain a list of all the drawing views that are in the view pallete in the active drawing. The user will then select the view they would like from the combo box and hit the command button and then the rest of the macro would run by taking the view, dropping on the sheet, exploding it, inserting BOM table, and add balloons to the view. I just can't figure out the code to use for the combo box/user form. Any help will be greatly appreciated.
John
SolidworksApi macros
From solidworks VBA, go to Insert (top toolbar) >>> Userform. Double click on the form and enter this code:
'************************************************************************************
'''
''' Code to run when user clicks the "OK" button
'''
Private Sub CommandButton1_Click()
'Do Your Code Here
MsgBox ComboBox1.Text
Unload Me 'Terminates and closes the form / Program
End Sub
'''
''' Code to run when the form initializes / loads.
'''
Private Sub UserForm_Initialize()
ComboBox1.Text = "
With ComboBox1 'Add your viewnames from Solidworks code here
.AddItem "View1"
.AddItem "View2"
.AddItem "View3"
End With
End Sub
'************************************************************************************
You can select different sub-routines for buttons, forms, etc... by selecting the first dropdown at the top of the code window (might say commandbutton or userform), and then choosing a different dropdown on the right dropdown (should say initialize or something else).
Michael,
Thanks for your help. That is just what I was looking for. I am going to use that as a jumping off point and see if I can build off it. Hopefully the language will become easier for me as I keep figuring things out. Thanks again.
John