Bagharmin
Board Regular
- Joined
- Nov 22, 2010
- Messages
- 168
I'm getting a subscript out of range error when trying to save a renamed workbook to my Desktop. Here's the code:
I get the error at the last line where I actually try to save the file. What am I doing wrong here? Everything's been properly DIM'd; I just haven't shown all that part of the code.
Many thanks.
Code:
' Open the previous month's Report
Filt = "Excel Files (*.xls*), *.xls*," & "Comma Separated Files (*.csv), *.csv," & "Text Files (*.txt), *.txt"
FilterIndex = 2
Title = "Please open the previous month's Report."
FileName = Application.GetOpenFilename(FileFilter:=Filt, FilterIndex:=FilterIndex, Title:=Title)
If FileName = False Then
MsgBox ("No file was selected.")
Exit Sub
End If
Workbooks.Open (FileName)
' Now give it a new name and save it.
Filt = "Excel Workbook (*.xlsx), *.xlsx"
FilterIndex = 1
Title = "Now give the Report and new name and save it."
TempName = FileName
FileName = Application.GetSaveAsFilename(TempName, Filt, FilterIndex, Title)
MsgBox (FileName)
ComboRpt = Right(FileName, Len(FileName) - InStrRev(FileName, "\"))
Workbooks(ComboRpt).SaveAs FileName
I get the error at the last line where I actually try to save the file. What am I doing wrong here? Everything's been properly DIM'd; I just haven't shown all that part of the code.
Many thanks.