Hello,
I am using Solidworks 2012. I am new to using Macros. This is also my first time using Solidworks Forums. I am trying to learn how to make a macro that will prompt Solidworks to open a browser that i can use to select a folder. I then want to be able to open each file in that folder, run an arbitrary block of code (I am not worried about the arbitrary code right now) and close each file. I've found that I if I hard-code a specific folder path as a string and call it "folder" I can utilize the following lines of code.
ChDir(folder) 'I believe this sets the folder as the directory of interest
swFilename=Dir(folder) 'This seems to define my String swFilename as the first file in the directory.
swFilename=Dir 'This seems to define my String swFilename as the next file in the directory.
I am able to set up a loop and use the commands Set swApp = Application.SldWorks, swApp.OpenDoc6 and swApp.CloseAllDocuments to open and close all documents in a desired folder. My problem is that I want to browse and select a folder to use, not hard-code it.
I was able to set up a simple program using that following lines of code...
Dim swApp As SldWorks.SldWorks
Dim myShell As New Shell32.Shell
Dim myFolder As Shell32.Folder3
Set myFolder = myShell.BrowseForFolder(0, "Select Folder!", 16)
Which launches a browser that I can use to select a folder. Instead of a String though, I get some sort of folder object which I call myFolder. But I can't use myFolder with the Dir function because the Dir function requires a String input. There should be an easy way to extract the file path of the folder as a string from myFolder. For whatever reason I have not been able to figure this out.
If someone could let me know how to get a file path as a String from a Folder Object I would greatly appreciate it. Or if anyone has an alternative method of creating the generic macro I explained above please let me know.
Thank you all in advance!