Macro which will increase a file name instance

Hello

I was wondering if anyone can help me with some script to automate the creation of a large assembly.

I have over 500 Parts which all need to be mated to the origin. Each Part is saved as an increasing number 1,2,3,4, etc. What I am trying to create is a process which:

- opens 20 files

- Mates files 1 to 20 to the origin

- closes the files

then

- opens the next 20 files

- mates files 21 to 40 to the origin

-closes the files

etc

I have been able to recored this sequence for 20 files but I am unable to work out how to automate the increase of the file name/numbers to the next batch sequence; ie files 1 (in the script) is increase to 21.

is this possible?

Bellow is an example scrip I have recorded. The aim of this example would be to automate the change of "File 1" to "file 2" in the script. I have attached a working with parts.

Option Explicit
' ******************************************************************************
' C:\Documents and Settings\Daniel.naylor\Local Settings\Temp\swx4768\Macro1.swb - macro recorded on 12/24/10 by daniel.naylor
' ******************************************************************************
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = _
Application.SldWorks
Set Part = swApp.ActiveDoc
Set Part = swApp.OpenDoc6("C:\Documents and Settings\Daniel.naylor\Desktop\Macro example\File 1.SLDPRT", 1, 0, "", longstatus, longwarnings)
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 21
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
swApp.ActivateDoc2 "File 1.SLDPRT", False, longstatus
Set Part = swApp.ActiveDoc
Part.WindowRedraw
Part.WindowRedraw
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
Part.ViewZoomtofit2
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 0
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
swApp.ActivateDoc2 "Assembly of file 1 and file 2.SLDASM", False, longstatus
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = Part.AddComponent("C:\Documents and Settings\Daniel.naylor\Desktop\Macro example\File 1.SLDPRT", -1.101432406472E-04, 8.063801402614E-05, 2.951833118914E-05)
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 0
swApp.ActivateDoc2 "File 1.SLDPRT", False, longstatus
Set Part = swApp.ActiveDoc
Set Part = Nothing
swApp.CloseDoc "File 2.SLDPRT"
swApp.ActivateDoc2 "Assembly of file 1 and file 2.SLDASM", False, longstatus
Set Part = swApp.ActiveDoc
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 0
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
Part.ShowNamedView2 "*Isometric", 7
Part.ShowNamedView2 "*Isometric", 7
End Sub

Any help or advice would be greatly appreciated  

Daniel

SolidworksApi macros