6 Replies Latest reply on Jan 18, 2017 6:20 PM by Nilesh Patel

    solidworks vba

    Adam Tesfay

      Hello everyone,

      I am new to this forum and I have zero experience with VBA in Solidworks or VBA in general. I was wondering if it’s possible to have a macro in Solidworks that would ask user to browse for excel file that has name of parameters on column A and the values on column B. once the excel is selected the macro would loop through column A and see if it exist in Solidworks active open doc(or open specific sw doc)  as a global variable if it does copy the value from column B else create the global variable from column A and B and move to next row and do the same. If this possible and not too much to ask I was hoping someone could provide me a macro? Or give me a guide with outline of the code structure? Thanks in advance.

      Sincerely

      Adam

        • Re: solidworks vba
          Christian Chu

          Do you have any Visual Basic programming experience?

          if you do, then this can be done by using windows 32 API

          • Re: solidworks vba
            Peter Kennedy

            I have a macro I use that sends information to Excel to look to verify that the information is valid then runs a macro in excel to generate a number and returns the value as a custom property in Solidworks. I use the following code to open excel:

             

            xlApp = CreateObject("Excel.Application")

             

            Set xlBook = xlApp.Workbooks.Open("File Location")

             

            Set xlSheet = xlBook.Sheets("Sheet Name")

             

            I pass information from the custom properties using:

             

            bool = swCustProp.Get4("Property Name", False, val, valout)

            xlSheet.Cells(2, 1).value = val

             

            This is what I use to pass to custom properties:

             

            swCustProp.Add3 "Property Name", swCustomInfoType_e.swCustomInfoText, Property Value, swCustomPropertyAddOption_e.swCustomPropertyOnlyIfNew

            swCustProp.Set "Property Name", Property Value

             

            I'm not sure about passing to a global variable, I'm sure it's possible but you'll have to figure that out.