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












 
yes it was the same.
 
OK, what about if you use "*.s*"? still no files found?
 
same thing......shows up, but nothing listed
 
Okay well I am lost at this point. I tried copying the file and some folders back ot the original location, and it runs but doesn't list the files in the folder anymore. Something has had to of changed somewhere. It still won't run through on my new shared drive, gives the runtime error every time. Should I try re-installing the DSO file??
 
Sorry, Puds. I'm just not able to reproduce your problem, so it's very difficult to try to debug from here. You could try reinstalling DSO, but I'm not sure that would help, especially if you don't seem to be finding any files. I'm able to access both network and local directories with no problems.
 
Handleman, I appreciate all of your help, I would have never had this thing working without you in the first place. Do you think however, that this could be a network problem with security/permissions? I did try to have it look in my c: instead of a network drive, and it still didn't find any files, but it didn't crash. I will try copying the actual file to my c: and then running it.
 
Tried c:\, still doesn't list any files. Can you maybe post your copy and I will copy and paste into my file. Maybe something small got changed by accident and I am just missing it.
 
It's really hard to say. If I were able to reproduce the problem, the next thing I would do is start at the beginning of the code and verify that every line was actually doing what it is supposed to do. Very frequently when you get an error message, the problem is that some other line of code is not doing what you expected it to.
 
Handleman, what references are you using with this app? Also, I can get it to run on my new shared drive finally, but it doesn't list any files, but it goes thorugh it without an error. Is there any way I can add an error checking code to it to see what is causing the problem?
 
Handleman, I basically rewrote the entire program, line by line to see if it was just a corrupt file. I have finally got the program working (must have been corrupt), but I still get errors only when it searches through specific file types such as .dwg (autocad) or .vnc (gibbscam). I am kind of making an assumption that this is because there is no references for those object types loaded? Is this a good thought? If so, I don't know if I can find the dll files for those programs, so is there anyway that I can just search only for solidworks files (*.sld) doesn't seems to work but I can return all of the file types (.sldprt, .slddrw, .sldasm if I set y equal to those types individually. Its really strange how this has all changed. I had no problems with any file types previously. Any thoughts?
 
Sorry, puds, but I'm really at a loss. I downloaded the file you posted, changed the search path to a folder with various types of files, and ran the code. All files, regardless of type, were listed in the spreadsheet. The other file types (dxf, txt, etc) were shown, just without any custom properties. Pretty much all you can do at this point is to test each line of the code to make sure it's doing what you expect. For example, near the beginning of your code you have the line:

Set OBJFILE = CreateObject("DSOFile.OleDocumentProperties")

To verify that it is at least doing something, you can follow that line with

Debug.Print OBJFILE Is Nothing

If your immediate window shows "True" then you know that the Set statement failed somehow. Next you have the line:

y="*.*"

you can verify that this statement worked correctly by the line

Debug.Print y

You should see *.* in the immediate window. You can do this sort of thing for every line until you find the line that is not behaving in the way you expect.

I used to use MsgBox a lot for this type of debugging. However, if you put a MsgBox inside a looping section of the code you'll have to do a lot of clicking while it goes through the loop. Debug.Print just outputs to the immediate window.
 
Handleman, I just want to check to see what references you have set in your file. Can you list them. This is my last option at this point. The fact that mine will run for any solidworks files (and I have the Sw_objects.dll reference loaded) makes me wonder if I am missing some windows dll that should be referenced or if I should maybe reload those dll or tlb files because they have been corrupted. This is more than a bit of a headache, but I need to get this sorted out. At this point it crashes on any other file extension besides solidworks files. Maybe that sparks an idea for you?
 
Found something that may be causing my problem?? Interop.DSOfile.dll is not registered or referenced. I tried ot reference in my application, but it gives an error cannot be referenced. When I try to register it using regsvr32 "c:\dsofile\INTEROP.DSOFILE.dll", I get this error:

"c:\dsofile\INTEROP.DSOFILE.dll" was loaded, but the dll registry point was not found. This file can not be registered.
 
Handleman,

Just another update, finally got it fixed enough to be able to use it again. I changed y="*.*" to y="*.sld*" and now it will display all solidworks types only. That is good enough for what we use it for, for now anyways. Thanks for all of your help. Maybe one day I will figure out why it stopped being able to run all file extensions. It is quite strange.

 
then it won't display anything at all. y="*.*" does work, however when the program finds a file type that is anything other than a solidworks file, it gives the error method open of object 'oledoecumentproperties' failed. I actually just tried out the dsofile demo that comes in the download package from microsoft, and even that doesn't work for any other file types besides solidworks. However the demo program did give me some more info on the error - it seems the problem is with the interop.dsofile.dll, which by the way I cannot get to register. here is the error from the demo:

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80030001): Unable to perform requested operation.
at DSOFile.OleDocumentPropertiesClass.Open(String sFileName, Boolean ReadOnly, dsoFileOpenOptions Options)
at FilePropDemoVB7.FilePropDemo.OpenDocumentProperties() in D:\CDBackup\Projects\dsofile\2.1\Samples\VB7\FilePropDemo.vb:line 524
at FilePropDemoVB7.FilePropDemo.cmdOpen_Click(Object sender, EventArgs e) in D:\CDBackup\Projects\dsofile\2.1\Samples\VB7\FilePropDemo.vb:line 724
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2407
CodeBase: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
FilePropDemoVB7
Assembly Version: 1.0.1.0
Win32 Version: 1.0.1.0
CodeBase: file:///C:/DsoFile/Demo/FilePropDemoVB7.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2407
CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
Interop.DSOFile
Assembly Version: 2.1.0.0
Win32 Version: 2.1.0.0
CodeBase: file:///C:/DsoFile/Demo/Interop.DSOFile.DLL
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 7.0.5000.0
Win32 Version: 7.10.6001.4
CodeBase: file:///c:/windows/assembly/gac/microsoft.visualbasic/7.0.5000.0__b03f5f7f11d50a3a/microsoft.visualbasic.dll
----------------------------------------
CustomMarshalers
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/windows/assembly/gac/custommarshalers/1.0.5000.0__b03f5f7f11d50a3a/custommarshalers.dll
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.


 
As I said, I downloaded your file and used it directly. The list of referenced DLLs is saved in the file. The only ones referenced in my copy are (in order, top to bottom):

Visual Basic for Applications
Microsoft Excel 11.0 Object Library
OLE Automation
Microsoft Office 11.0 Object Library
DSO OLE Document Properties Reader 2.1

Interop.DSOFile.DLL is not used by anything except the demo program. I can rename that file and the code still runs. Have you tried this on other computers? Have you verified that your DSOFile.DLL is not corrupt?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top