You can do this using Sw API or Excel here is a code I used to open an
excel document and search a row for a specific number it may help get
you started. What you have to do is in VBA for Excel go up to tools
References and find the Solidworks References. Once you have
referenced these files you can program your VBA macro just as you
would have from Solidworks VBA. It works the other way also. From
Solidworks VBA add the Excel References.
The example below Works out of Solidworks
1) Opens excel
2) Searches the A column for a string
3) pulls the cell next to the first found
4) closes excel (if you use this code make sure you close excel
you endup having 20 open instances of excel one for each time it
5) returns the value of the cell that was pulled
Dim exclApp As Excel.Application
Dim Wkbk As Excel.Workbook
Dim Sheet As Excel.Worksheet
Public Cell As String
Dim actvCell As Range
Dim text As String
sub main ()
msgbox GetMatlDesc ("500253")
Function GetMatlDesc(srchText As String) as String
If Not Mid(srchText, 6, 1) = "" Then Else Exit Sub
Set exclApp = Excel.Application
exclApp.Workbooks.Open ("C:\MATERIAL LIST FROM FS.xls")'create
'in the "A"
'next to it
Set Wkbk = exclApp.ActiveWorkbook
Set Sheet = exclApp.ActiveSheet
On Error GoTo ErrHandler
Cell = Sheet.Range("A:A").Find(srchText).Address(False, False)
Set actvCell = Sheet.Range(Cell)
Set actvCell = actvCell.Offset(0, 1)
Cell = actvCell.text
Cell = "No Material Specified"
GetMatlDesc = Cell
Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here.
All logos and trade names are the property of their respective owners.