AnsweredAssumed Answered

Open Solidwork file from Excel VBA

Question asked by David Johnson on Mar 29, 2016
Latest reply on Feb 25, 2019 by Niels Raahauge

Hello All.  I've been using Solidworks for 15 years but am new to API.  We have an Excel spreadsheet that we use to open Solidworks files.  When the VBA code in Excel was written the author simply used a hyperlink to open a Solidworks file.  When we upgraded to 2016 the hyperlink method stopped working.  If someone could help me figure out how to open a Solidworks file in VBA I believe I could modify our existing code. 


I've copy/pasted below the sample code from API Help.  I can't get it to work.  Excel VBA throws up a compile error "Variable not defined" and it highlights "swDocPART" from the OpenDoc6 line.  I've attached screenshots of the compile error and of the references I've loaded.  I'm looking for a very simple method to open files.  I really don't care about making the current directory the working directory.

Dave J


Option Explicit

Dim swApp As SldWorks.SldWorks
Dim doc As SldWorks.ModelDoc2
Dim fileerror As Long
Dim filewarning As Long

Sub main()

    Set swApp = Application.SldWorks
    swApp.Visible = True

    Set doc = swApp.OpenDoc6("J:\Approved\3D\060-0023.sldprt", swDocPART, swOpenDocOptions_Silent, "", fileerror, filewarning)



End Sub