AnsweredAssumed Answered

Macro to control part file name and location using text box via user form

Question asked by John Shaw on Aug 22, 2019
Latest reply on Aug 23, 2019 by John Shaw

Does anyone out there know of a way to control the file save location and file name via a user form using text boxes? 

I want the macro to save the part to a specified file name and save to a specified location the user inputs. I am a beginner when it comes to programming so there may be something majorly wrong with my code that I may not be aware of. The Code is pasted below. My current result is it saves the part file but it does not save with the correct name or location. Any help is appreciated. Also I am using 2017 SolidWorks if that helps any.


Private Sub CommandButton1_Click()


Set swApp = Application.SldWorks

' Save Out Model

      Dim PartName As String
      Dim PartLocation As String


      FileName = TextBox1.Text
      SaveLocation = TextBox2.Text

      'Set Save Location and File Name
      Set swModel = swApp.ActiveDoc
      Set swDocExt = swModel.Extension
      swModel.Extension.SaveAs SaveLocation + FileName + ".sldprt", 0, 1, Nothing, intErrors, intWarnings

Unload Me

End Sub