save files incrementally in excel

R

r.brydges

hello,

i have a loop moving through a folder of files. i have 130 files and
each opens incrementally, dumps into a template file and then I want to
save the newly filled template as trial 1....trial 130. however, the
save function keeps saving to trial 1 for each trial (i.e., the save as
function does not change the name incrementally). Does anyone know how
to do this?

My code is:

Sub ryan_macro()
Application.ScreenUpdating = False
Dim i As Integer
Dim wbResults As Workbook
With Application.FileSearch
.NewSearch
.LookIn = "C:\Documents and Settings\RyanB\My
Documents\Thesis\Test"
.SearchSubFolders = False
.Filename = "*.txt"
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(i))
ActiveCell.SpecialCells(xlLastCell).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.Copy
ChDir "C:\Documents and Settings\RyanB\My Documents\Thesis"
Workbooks.Open Filename:= _
"C:\Documents and Settings\RyanB\My
Documents\Thesis\thesis - bump analysis1.xls"
Range("D1").Select
ActiveSheet.Paste
ActiveWorkbook.SaveAs Filename:= _ 'MY PROBLEM AREA
"C:\Documents and Settings\RyanB\My
Documents\Thesis\Test\trial(i).xls", _
FileFormat:=xlNormal, Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
ActiveWindow.Close
Next i
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
End Sub



VBA newbie in need of help!!
Thanks. :)
 
B

Bob I

Just a thought, try Dim TrialX as Integer and set it to "i" for use in
the place of "i" in the filenaming command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top