update an embedded excel spreadsheet by changing a custom property in a SW drawing

I have an embedded spreadsheet in a solidworks drawing that reads a custom property. 

I use the Custom Properties Tab to allow users to enter "Description", "Units", and "type" from dropdown lists.

(Note: There is logic in the embedded excel spreadsheet that will assign a different tolerance and display based on the dropdown selections.  A general table is not capable of providing this level of logic (a simple look up table) and since the drawing is a template, I cannot use a design table.)

If I change andy of the custom properties for "description", "Units", or "type", the only way for it to update is to save the SW drawing, close it, and reopen it.

Is there a way to update the excel spreadsheet automatically when you change the custom property?

Another user provide me with the code to add the SW custom property to the excel spreadsheet.  It works, but it doesn't seem to work "on-the-fly"

Private Sub Workbook_Open()
UpdateCells
End Sub

' We need to call this whenever SW updates a custom property
Sub UpdateCells()

Dim swApp As SldWorks.SldWorks
Set swApp = New SldWorks.SldWorks
Dim swModel As ModelDoc2: Set swModel = swApp.ActiveDoc
' Gets the custom property description and puts it into the A1 cell
Workbooks(1).Worksheets(1).Range("A1").Value = swModel.CustomInfo2("", "Description")
Workbooks(1).Worksheets(1).Range("A2").Value = swModel.CustomInfo2("", "Units")
Workbooks(1).Worksheets(1).Range("A3").Value = swModel.CustomInfo2("", "type")
End Sub

I would greatly appreciate anyone who can come up with a clever solution to my dilemna.

thanks,

SolidworksApi macros
Answers 5
SF
SF 2010-11-19 Best Answer

If you could send a example file of your drawing / drawing template it would help to understand what you actually have in the excel file.

SF
SF 2010-11-19

Attached is the drawing template and custom properties tab along with an example of the drawing another user sent me with the VBA code that actually works.

It is not working in my Aavid A1 - horiz -1st Angle.DRWDOT embedded spreadsheet.  I don't know why, but when I try to run the VBA it gives me a compilation error that says,   User-defined type not defined and highlights Sub UpdateCells() in yellow and highlights Dim swApp As SldWorks.SldWorks in blue.

SF
SF 2010-11-20

I do not believe that you have any benefits using excel on this kind of solution. Instead look at events from API help and build up simple form that is displayed when customproperties have changed and do your magic there. Opening up embedded excel spreadsheet launched by some event that is straightly connected of model/drawing changes can cause you a.) performance issues b.) stability issues. If some table is needed for storing/showing data, use SWx general table for that.

SF
SF 2010-11-22

It seems as though I have the answer but need one more event to trigger the embedded spreadsheet to kick off.  If there is a way to do that through the action of changing a custom property or updating the model rather than firing a macro you've accomplished a level of automation.  However, using macro to fill a property table would be fine.  I think what you are suggesting is rather using excel to provide the lookup table function or conditional statements, build these into the macro code.  So my question is, can you send me some examples of how to do this in API?

SF
SF 2010-11-22

My suggestion is that you build add-in that does trigger solidworks events and when properties have been changed event is fired and you can show the userform where you have your needed things. There is add-in templates available look for those.