Export Part #s to Excel from Solidworks
Export Part #s to Excel from Solidworks
(OP)
Hi I am new to this forum.
There seem to be alot of nice smart people here so i was hoping that someone could help me with task i have been having problems with.
I have an assembly and i need a macro to export the part numbers and descriptions of all the parts to an excel sheet, I don't want to do it with a BOM because i have other code that i need to put in this macro as well. Could someone help me with this?
There seem to be alot of nice smart people here so i was hoping that someone could help me with task i have been having problems with.
I have an assembly and i need a macro to export the part numbers and descriptions of all the parts to an excel sheet, I don't want to do it with a BOM because i have other code that i need to put in this macro as well. Could someone help me with this?





RE: Export Part #s to Excel from Solidworks
-handleman, CSWP (The new, easy test)
RE: Export Part #s to Excel from Solidworks
RE: Export Part #s to Excel from Solidworks
RE: Export Part #s to Excel from Solidworks
-handleman, CSWP (The new, easy test)
RE: Export Part #s to Excel from Solidworks
But what i actually want to do is have an assembly open traverse each part look for sheetmetal features and if it finds one get the perimeter and the number of holes and do some calculations based on that then export the Part number, the description, the size of the part and configuration name. I have figured out how to get most of that stuff, I just don't know how to send it to excel. So it won't really help me with the bill of materials.
RE: Export Part #s to Excel from Solidworks
-handleman, CSWP (The new, easy test)
RE: Export Part #s to Excel from Solidworks
RE: Export Part #s to Excel from Solidworks
Dim exApp As Excel.Application
Dim sheet As Excel.Worksheet
These two lines tell your SW macro that it's going to be working with Excel.
Set exApp = New Excel.Application
This line starts up Excel. Now every time you refer to the exApp variable, it's connected to the Excel application.
There are a few "If Not ___ is Nothing Then" statements. They are just in there to make sure that the stuff that the macro is telling Excel to do is actually getting done.
exApp.Visible = True
This line makes sure that Excel is visible to the user. Otherwise, Excel will open in the background and you won't be able to interact with it - i.e. save the worksheet once you're done putting values in it.
exApp.Workbooks.Add
This line creates a new Excel Workbook inside the Excel Application.
Set sheet = exApp.ActiveSheet
This line sets the object variable "sheet" equal to the new workbook that was just created.
sheet.Cells(1, 2).Value = "X"
This line puts the text "X" into cell B2 (row 1, column 2) of the new worksheet. This is how you actually put your values in the worksheet - one cell at a time.
-handleman, CSWP (The new, easy test)
RE: Export Part #s to Excel from Solidworks
I like to put things like this in functions because then it is neater it you are searching for something it is alot easier to find. This is what i have and it make sence that it would make a new sheet each time.
Function ExportToExcel(ByVal compName As String)
Dim exApp As Excel.Application
Dim sheet As Excel.Worksheet
Set exApp = Excel.Application
exApp.Visible = True
exApp.Workbooks.Add
Set sheet = exApp.ActiveSheet
sheet.Cells(1, 2).Value = compName
End Function
RE: Export Part #s to Excel from Solidworks
Dim exApp As Excel.Application
Dim sheet As Excel.Worksheet
Set exApp = Excel.Application
exApp.Visible = True
exApp.Workbooks.Add
Set sheet = exApp.ActiveSheet
Then, inside your traversal loop, when you figure out what data you want to put into Excel you just use that one line
sheet.Cells([row],[col]).Value = [whatever]
Also, inside your loop you are going to have to keep track of the row/column where you want to put your data in the spreadsheet and change the numbers for [row] and [col] appropriately. Otherwise, you'll just keep overwriting the data in cell B1. (sorry, my previous post typo'd to B2 instead of B1)
-handleman, CSWP (The new, easy test)
RE: Export Part #s to Excel from Solidworks
Dim exApp As Excel.Application
Dim sheet As Excel.Worksheet
Set exApp = Excel.Application
exApp.Visible = True
exApp.Workbooks.Add
Set sheet = exApp.ActiveSheet
Row = 1 + i
col = 1
sheet.Cells([Row], [col]).Value = [whatever]