Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations JAE on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

SW Custom Property Linking in Excel's VB 11

Status
Not open for further replies.

puds

Mechanical
Joined
Jun 25, 2007
Messages
40
Location
CA
I am not a programmer at all, however I have managed to create myself and my company a quick and easy way of tracking our drawings. I simply created a spreadsheet in Excel that automatically updates on open & lists all files in our drawing vault folder by their filename and adds a hyperlink to each of these files. I now want to add the corresponding description, customer name & project # from the custom properties of each of the solidworks files so that they will display in the spreadsheet also, therefore giving us a means of finding our documents without knowing the exact part number. Right now, I have the spreadsheet working so that column A lists the files and hyperlinks them, column B lists the Last Modified Date & column C shows the file path. Column D heading shows Description, Column E heading shows Customer & Column F shows Project, just like they should. However I do not understand how I can retrieve the custom property values and have them added into my spreadsheet. If anybody could help, that would be awesome. Here is my code so far:

Private Sub WORKBOOK_OPEN()
' Searches the selected folders and sub folders for files with the specified
'extension. .xls, .doc, .ppt, etc.
'A new worksheet is produced called "File Search Results". You can click on the link and go directly
'to the file you need.
Dim i As Long, z As Long, Rw As Long
Dim ws As Worksheet
Dim y As Variant
Dim fLdr As String, Fil As String, FPath As String

y = "*.*"
If y = False And Not TypeName(y) = "STRING" Then Exit Sub
Application.ScreenUpdating = False

'**********************************************************************
'fLdr = BrowseForFolderShell
fLdr = "P:\DRAWING_VAULT"

'**********************************************************************
With Application.FileSearch
.NewSearch
.LookIn = fLdr
.SearchSubFolders = False
.Filename = y
Set ws = ThisWorkbook.Worksheets.Add(Sheets(1))
On Error GoTo 1
2: ws.Name = "TMC_DRAWING_LIST"
On Error GoTo 0
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Fil = .FoundFiles(i)
'Get file path from file name
FPath = Left(Fil, Len(Fil) - Len(Split(Fil, "\")(UBound(Split(Fil, "\")))) - 1)
If Left$(Fil, 1) = Left$(fLdr, 1) Then
If CBool(Len(Dir(Fil))) Then
z = z + 1
ws.Cells(z + 1, 1).Resize(, 6) = _
Array(Dir(Fil), _
FileDateTime(Fil), _
FPath, _
'***this is where I would assume I need to add the callouts for description, customer & project**
)



ws.Hyperlinks.Add Anchor:=Cells(z + 1, 1), _
Address:=.FoundFiles(i)
End If
End If
Next i
End If
End With

ActiveWindow.DisplayHeadings = False

With ws
Rw = .Cells.Rows.Count
With .[A1:F1]
.Value = [{"FILE NAME (CLICK TO OPEN)","LAST MODIFIED", "PATH"," FILE DESCRIPTION","CUSTOMER","PROJECT/WORKORDER NO."}]
.Font.ColorIndex = vbBlack
.Font.Bold = True
.Font.Size = 11
.Cells.Interior.Color = vbGreen
.EntireColumn.AutoFit
.HorizontalAlignment = xlCenter
End With
.[G1:IV1 ].EntireColumn.Hidden = True
On Error Resume Next
Range(Cells(Rw, "A").End(3)(2), Cells(Rw, "A")).EntireRow.Hidden = True
Range(.[A2 ], Cells(Rw, "C")).Sort [A2 ], xlAscending, Header:=xlNo
End With

Application.ScreenUpdating = True
Exit Sub
1: Application.DisplayAlerts = False
Worksheets("TMC_DRAWING_LIST").Delete
Application.DisplayAlerts = True
GoTo 2
End Sub












 
I do not have an answer for you, but I am wandering why you are not using PDM?

Bradley
SolidWorks Premim 2007 x64 SP4.0
PDM Works, Intel(R) Pentium(R) D CPU
3.00 GHz, 4 GB RAM, Virtual memory 12577 MB, nVidia 3400
 
You need to use either dsofile.dll or swDocumentMgr.dll function calls. DSOfile might be a little faster, but I'm really not sure. If you'll use the Google search on these forums for DSOfile you should be able to find enough to get you started. Good luck!
 
We don't have PDMworks on all of our machines, so it doesn't make sense to use it. Plus, we are a very small shop, so the extra 10g's or whatever it is to upgrade to office pro doesn't make sense for us. If I can get this last portion of the code working, this is just as good for us as PDM would be. We don't have that many files, but enough that we need to track them. I'll try to check out the DSOfile. Thanks.
 
You don't need active on all of your machines. You just need a single site license or two to share between your systems. I highly recommend looking into using PDMWorks as your engineering department rev control and file storage because on what you've described here.

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
 
Correction: "You don't need PMDWorks active on all of your machines. You just need a single site license or two to share between your systems. I highly recommend looking into using PDMWorks as your engineering department rev control and file storage, based on what you've described here." too early in the morning here lol

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
 
I have looked at PDM works and it doesn't look that great to be honest. I want a simple list that I can go to and sort quickly in order to find what document I am looking for. We use our drawing numbers as filenames, so by looking at the file in a folder, there is no way to tell what it unless you open SW. Using the spreadsheet, we can sort by customer, description, etc to find what file we are looking for then just click the hyperlink to open the document. PDMworks is overkill for what we are using it for. Somebody please let me know if you have any suggestions on the exact code that I would need to add to my code above to have it list the custom properties I mentioned in my first posting. Thanks!
 
Well, it should really be said that it appears you are trying to re-invent the wheel. It sounds like you are trying to make a basic PLM with a small macro. This is like Agile, Oracle, PeopleSoft, SAP, etc. There's a reason why these companies exist. :) Making PLM's it's not easy to do. Anyways, Good Luck!

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
 
Matt, well said.
I am so glad we are using PDM. A star for you.

Bradley
SolidWorks Premim 2007 x64 SP4.0
PDM Works, Intel(R) Pentium(R) D CPU
3.00 GHz, 4 GB RAM, Virtual memory 12577 MB, nVidia 3400
 
What's wrong with you guys? The man asked a simple question, you don't have an answer but you keep telling him how stupid he is because he thinks different than you do. Are you trying to chase him away from this forum?
 
I was wondering the same thing.....I just want to get some help on my problem. I have heard the same story about PDMworks from our annoying reseller a thousand times. If anybody could help me, it would be greatly appreciated. Once I have it working, I would be more than happy to post it for whoever may be able to utilize as well (perhaps for those who don't have PDMworks). Thanks folks.
 
As mentioned in handleman’s first post swDocumentManager.dll is an alternative to DSOfile.dll. They have different calls and different functionality, but both should be able to accomplish what you want.

If you are only going to be opening this spreadsheet on computers with SolidWorks and you do not want to install DSOfile.dll on them you could use the swDocumentManager.dll that is installed with SolidWorks explorer. See thread559-175535 for the chunk of code by handleman. It should be a good starting point. If you are using a version of SolidWorks prior to 2007, you will need to e-mail SolidWorks API tech support to get a key to make it work. As in handleman’s example, you would also have access to configuration specific custom properties.

Personally I would use DSOfile.dll since you do not appear to need the configuration specific properties.

Eric
 
Well I have finally got it working a little more. As you will see in my code below, I have sorted out the DSOfile side of it, however I need to now tie that into my array. Right now, my array will only list the custom properties of the file I have named with an absolute path as I point out in my code. How do I change the code so I can make sure that fil = each file in the array so that my excel list will list the data corresponding to each file. Please help me out.

Sub WORKBOOK_OPEN()


Dim i As Long, z As Long, Rw As Long
Dim ws As Worksheet
Dim y As Variant
Dim fLdr As String
Dim fil As String
Dim DSO As DSOFile.OleDocumentProperties
Dim FPath As String
Set DSO = New DSOFile.OleDocumentProperties
fil = "I HAVE TO PUT AN ABSOLUTE FILE PATH HERE"
DSO.Open SFileName:=fil
Dim Object As String
Set OBJFILE = CreateObject("DSOFile.OleDocumentProperties")
y = "*.*"
If y = False And Not TypeName(y) = "STRING" Then Exit Sub
Application.ScreenUpdating = False

'**********************************************************************
'fLdr = BrowseForFolderShell
fLdr = "P:\DRAWING_VAULT"

'**********************************************************************

With Application.FileSearch
.NewSearch
.LookIn = fLdr
.SearchSubFolders = False
.FileName = y

Set ws = ThisWorkbook.Worksheets.Add(Sheets(1))
On Error GoTo 1
2: ws.Name = "TMC DRAWING LIST"

On Error GoTo 0
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
fil = .FoundFiles(i)
'Get file path from file name

FPath = Left(fil, Len(fil) - Len(Split(fil, "\")(UBound(Split(fil, "\")))) - 1)
If Left$(fil, 1) = Left$(fLdr, 1) Then
If CBool(Len(Dir(fil))) Then
z = z + 1
ws.Cells(z + 1, 1).Resize(, 8) = _
Array(Dir(fil), _
DSO.SummaryProperties.DateLastSaved, _
DSO.CustomProperties.Item("DESCRIPTION").Value, _
DSO.CustomProperties.Item("CUSTOMER").Value, _
DSO.CustomProperties.Item("PROJECT").Value, _
DSO.CustomProperties.Item("USERDEFINED1").Value, _
DSO.CustomProperties.Item("USERDEFINED2").Value, _
DSO.CustomProperties.Item("DRAWNBY").Value)


ws.Hyperlinks.Add Anchor:=Cells(z + 1, 1), _
Address:=.FoundFiles(i)
End If
End If
Next i
End If
End With

ActiveWindow.DisplayHeadings = False

With ws
Rw = .Cells.Rows.Count
With .[A1:H1]
.Value = [{"FILE NAME (CLICK TO OPEN)","LAST MODIFIED"," FILE DESCRIPTION","CUSTOMER","WORKORDER NO.","COMPUTER ID NO.","CUSTOMER DWG NO.","AUTHOR"}]
.Font.ColorIndex = vbBlack
.Font.Bold = True
.Font.Size = 11
.Cells.Interior.Color = vbGreen
.EntireColumn.AutoFit
.HorizontalAlignment = xlCenter
End With
.[I1:IV1 ].EntireColumn.Hidden = True
On Error Resume Next
Range(Cells(Rw, "A").End(3)(2), Cells(Rw, "A")).EntireRow.Hidden = True
Range(.[A2 ], Cells(Rw, "C")).Sort [A2 ], xlAscending, Header:=xlNo
End With

Application.ScreenUpdating = True
Exit Sub
1: Application.DisplayAlerts = False
Worksheets("TMC DRAWING LIST").Delete
Application.DisplayAlerts = True
GoTo 2
End Sub






 
Just move the code that retrieves custom properties into the "for" loop.
 
I moved the code to the "for" loop and now it gives an error that says the property "description" does not exist. It was working before when I just gave it an absolute path for a filename.
 
It will give that error when it comes across a file that doesn't have the description entered. You'll have to test for the existence of each property before you try to access it.
 
how exactly is that done?! LOL
 
Try replacing each

DSO.CustomProperties.Item("[name]")

with

iif(not DSO.CustomProperties.Item("[name]") is nothing, DSO.CustomProperties.Item("[name]").Value, "")


That's all one line. It's sort of ugly programming, but it's the simplest way to fit it into your code.

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top