Saving


Posted by Allan Habedank on August 29, 2001 11:06 AM

I would like to know how to write a macro that would save a template to the hard drive several times from within the worksheet. ie: smith1,smith2,smith3,etc.without having to go through the save as command.



Posted by Pierre on August 30, 2001 12:04 AM

Hello, try the following code.

Sub SaveAsManyTimes()

Dim s As String
Dim Path As String
Dim i As Integer
Dim i2 As Integer

'to get without the ".xls" , the function will fetch the string before the first "."
s = Left(ActiveWorkbook.Name, InStr(1, ActiveWorkbook.Name, ".", vbTextCompare) - 1)

'put your own path here
Path = "C:\Temp\"

'select the number of times you want to save your file
Do While i < 1<br> i = Val(Trim(InputBox("How many times do you want to save your file?")))
Loop

'Save as many times
For i2 = 1 To i
ActiveWorkbook.SaveAs FileName:=Path & s & i2, FileFormat:=xlTemplate
Next i2

End Sub