Spliting variables
Posted by John on February 01, 2002 5:42 AM
I am trying to create a backup file.
I use Application.GetSaveAsFilename to get the filename
I then saveas, and open the original. The problem occurs when I try to close down the backup file. I have the full filepath name but all I need for the close function is thelast bit e.g. book1.xls.
How can I get this from the full path variable?
Code is below if anyone wants to see it...
Cheers
John
Sub backup()
Application.ScreenUpdating = False
On Error GoTo ErrorHandler ' Enable error-handling routine.
'Save the current workbook as the BPA Backup
ActiveWorkbook.Save
fname = Application.GetSaveAsFilename
ActiveWorkbook.SaveAs Filename:=fname, _
FileFormat:=xlExcel7, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
MsgBox (fname)
Workbooks.Open(Filename:="Business Plan Reporting Tool TestTwo.xls").RunAutoMacros Which:=xlAutoOpen
Workbooks(fname).Close SaveChanges:=False
Application.ScreenUpdating = True
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
MsgBox ("An error ocurred during the back up process. Please Try Again.")
Exit Sub
End Sub