How to select dimensions and export to excel or access
How to select dimensions and export to excel or access
(OP)
I am trying to write a macro that will allow me to Export only the selected dimensions to a table or database. Im new
to vba so much help would be greatly appreciated. Also I am using solidworks 2003.






RE: How to select dimensions and export to excel or access
RE: How to select dimensions and export to excel or access
RE: How to select dimensions and export to excel or access
CODE
SolidWorks Constant Type Library
Microsoft Excel 11.0 Object Library (again may be different for you, I have Office 2003 installed).
In the code window type (or cut and paste) the following code.
CODE
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDim As SldWorks.Dimension
Dim xlApp As Excel.Application
Dim xlWorksheet As Excel.Worksheet
Dim AtIndex As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set xlApp = GetObject(, "excel.application")
Set xlWorksheet = xlApp.ActiveSheet
For AtIndex = 1 To swSelMgr.GetSelectedObjectCount
Set swDim = swSelMgr.GetSelectedObject5(AtIndex).GetDimension
xlWorksheet.Cells(1, AtIndex) = swDim.value
Next
End Sub
Now open a blank Excel workbook, select a few dimensions in SolidWorks and run the macro. I hope this helps.
Some final thoughts. Since you are new to SW API programming, I would suggest you do a search on "example" in the API help. There are a lot of good examples that you can learn from. You can also look in the FAQ's on this site as well as the SolidWorks web site for more examples.
SA
RE: How to select dimensions and export to excel or access