Here is what I want to do:
Using VB in Excel,
1) Find a directory and obtain a list of the Solidworks files in it
- this I can do.
2) Run down the list of files and query the configuration name list for each
one(without having to open each one & set a model object)
- this I don't know how to do. However, I do have the SW references working in
Excel. The question is, does a method exist for doing this.
3) Display the resulting lists in Excel - no problem there.
Does anyone have any suggestions for number 2? Is it possible?
It turns out it was not rocket science.
This is the code I have in an Excel Spread sheet.
Note that I used a literal string for "fs.lookin".
Anyone using it would have to change this according to their needs.
If you have a lot of files to go through, this thing can take a while.
You need to make column B in Excel of type "text" so that you can
order by that column & have them come out in a nice logical order,
that is, without all the numbers coming first.
You also have to add the Sldworks 2004 Type Library in Excel VBA.
Depending on how many files you have, this can take a while to run.
Dim i As Long
Dim j As Long
Dim k As Long
Dim fs As Object
Dim swApp As SldWorks.SldWorks
Dim vConfName As Variant
Dim strAllFiles() As String
Dim strSelFiles() As String
Dim lngConfigCount As Long
Set swApp = CreateObject("SldWorks.Application")
Set fs = Application.FileSearch
.LookIn = "N:\ENGINEERING\00 - VAULT\Solidworks Files\"
.SearchSubFolders = True
.Filename = "*.sldprt;*.sldasm;*.prt;*.asm"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
If i > UBound(strAllFiles) Then
ReDim Preserve strAllFiles(UBound(strAllFiles) + 256)
strAllFiles(i) = .FoundFiles(i)
MsgBox "There were no files found."
j = 1
For i = 1 To UBound(strAllFiles)
If InStr(strAllFiles(i), "~$") = 0 Then
'excludes "those" files
ReDim Preserve strSelFiles(j)
strSelFiles(j) = strAllFiles(i)
j = j + 1
k = 2
'leaves the 1st row empty for titles in Excel Spreadsheet
For i = 1 To UBound(strSelFiles)
lngConfigCount = swApp.GetConfigurationCount(strSelFiles(i))
If lngConfigCount > 1 Then
'ignore files with only one configuration
vConfName = swApp.GetConfigurationNames(strSelFiles(i))
For j = 0 To UBound(vConfName)
If vConfName(j) <> "Default" Then
'don't list "Default" configurations
Range("A" & k).Value = strSelFiles(i)
Range("B" & k).Value = vConfName(j)
k = k + 1
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.