Running a macro on all files in in a folder

Hi,

Forgive me if this is the wrong place for this request, also pleasebe gentle as this is the first time I have gotten involved in"coding" anything ever!

I've hacked about someone elses macro to take the filename and addit as a custom property, this works fine.

I would like to be able to run this macro and run it on all thefiles in a folder. We currently have thousands of parts anddrawings and I am trying to automate the renaming of them all tounique numbers prior to implementing PDMworks in early June.

So the simple question is this, is it possible to run a macro onall the files in a folder? If it is how do I do it? (even if Icould be pointed in the right direction that would be appreciated)

Many thanks,

Mike

SolidworksApi macros
Answers 6
IK
IK 2009-04-09 Best Answer
SF
SF 2009-04-09
Woops, sorry I missed that. Will try to get that to work first
SF
SF 2009-04-09
You can also use BatchProcess to do exactly this; batch runany number of macros on files/folders/assemblies and theirreferences, or custom lists
DB
DB 2009-04-09
You can also check out Lenny's site:
http://www.lennyworks.com/solidworks/default.asp?ID=20

for the PartNoProperty macro. He specifically tweaked one of hisother macros so I could do exactly what you want above. That newmacro is PartNoProperty.
RS
RS 2009-04-09
If you are working in VBA, you need to learn about theFile System Object. This object gives you access to drives,folders, and files. You can use it to enumerate files in a folder.

You will need to add a reference to MS Scripting Runtime libraryunderTools --> References in your VBA window.

http://www.techbookreport.com/tutorials/fso1.html
DM
DM 2009-04-10
here is another way

Dim Fold As String
Dim FileType As String

Sub main()
'Folder Name. Change to folder that has SolidWorks files
Fold = "C:\"
FileType = "*.*"
'This first time prints all files
GetFiles
Debug.Print "*******************"
'Prints all files that end with prt
FileType = "*.*prt"
GetFiles
End Sub

Sub GetFiles()
Dim FileName As String
FileName = Dir(Fold & FileType)
Do While FileName <> ""
Debug.Print FileName
FileName = Dir
Loop

End Sub

Dan