Home » excel » excel vba – How to refer to a relative path in SolidWorks VBA

excel vba – How to refer to a relative path in SolidWorks VBA

Posted by: admin April 23, 2020 Leave a comment

Questions:

I am writing a macro in SolidWorks VBA that is supposed to open all the parts of an assembly and update their design tables. When the assembly and parts are copied to a new location, I want the macro to open the new (copied) parts in their new location. How do I refer to a relative path for the parts instead of an absolute path.

Or: How do I program VBA to change the file location of the parts to the current folder?

I’ve found some info on how this works in Excel VBA, yet I can’t seem to translate this to SolidWorks VBA.

Dim folderpath As String
folderpath = Application.Activeworkbook.Path

I can’t figure out with what I should replace “ActiveWorkbook” to get the location of the current assembly. Searching the object browser in SW VBA doesn’t show anything usefull either.

How to&Answers:

You’ll want to use swModel.GetPathName. Here’s an example.