AnsweredAssumed Answered

How to break the link of a Design Table to External Spreadsheet

Question asked by Mike Smith on Mar 11, 2016

I have written a macro to update the links in the cells of my design table with an external spreadsheet and now I want to add some code to break the current link of the Design Table to an Excel spreadsheet. I have tried using LinkToFile = False but this does not break the link, when I check the setting the "Link to file" box is still checked. Am I doing something wrong or is this a broken feature of the SolidWorks API? Here is the code I have and everything works except the LinkToFile = False.


Dim swApp           As SldWorks.SldWorks

Dim Part            As SldWorks.ModelDoc2

Dim boolstatus      As Boolean

Dim newLinkPath     As Variant

Dim currentLinks    As Variant

Dim swModel         As SldWorks.ModelDoc2

Dim designTable     As SldWorks.designTable

Dim xlWS            As Excel.Worksheet

Dim xlWB            As Excel.Workbook

Dim link            As String


Sub main()

Set swApp = _


Set swModel = swApp.ActiveDoc


'Get the current working directory and add the file the link will be updated to

newLinkPath = CurDir$ & "\Layout.xlsx"


'Open Design Table

Set Part = swApp.ActiveDoc

Set designTable = Part.GetDesignTable

designTable.LinkToFile = False  'This is the code that doesn't work


Set xlWS = designTable.Worksheet

Set xlWB = designTable.Worksheet.Parent



'Get current links to external Excel Spreadsheet

currentLinks = xlWB.LinkSources(xlExcelLinks)

link = Join(currentLinks)


If StrComp(link, newLinkPath, vbTextCompare) = 0 Then


MsgBox "Links are up to date"




    'Update Design Table link to external spreadsheet

    xlWB.ChangeLink link, newLinkPath, xlLinkTypeExcelLinks


End If



End Sub