VB Statement for opening multiple files of type?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to write a VB script in Excel that will open up all files with a
..rpt extension, then format them in a particular way, then save them as .xls
files in a separate folder. I have been able to script the formatting of the
opened files, but I would like Excel to open all the files in a certain
folder that has the .rpt extension. Any suggestions on how to write this?
 
Sub HandleRPT()
Dim sPath as String, sName as String
Dim bk as Workbook, s as String
sPath = "C:\Myfolder\"

sName = Dir(sPath & "*.rpt")
do while sName <> ""
set bk = workbooks.Open(sPath & sName)
' process bk
s = left(sName,len(sName)-4)
bk.SaveAs sPath & s & ".xls", xlWorkbookNormal
bk.close Savechanges:=False
sName = Dir
Loop
End sub
 
This is poetic. It works fine now. Thanks!



Tom Ogilvy said:
Sub HandleRPT()
Dim sPath as String, sName as String
Dim bk as Workbook, s as String
sPath = "C:\Myfolder\"

sName = Dir(sPath & "*.rpt")
do while sName <> ""
set bk = workbooks.Open(sPath & sName)
' process bk
s = left(sName,len(sName)-4)
bk.SaveAs sPath & s & ".xls", xlWorkbookNormal
bk.close Savechanges:=False
sName = Dir
Loop
End sub
 

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

Back
Top