Save workbook with a predefined name

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

Guest

Hi this should be easy.

My workbook has 5 worksheets. I use a macro to delete rows from a worksheet.
When its done deleting id like to save the workbook with a different name (in
the same folder where the original workbook is).

the name should be the original workbooks name and " - student1". Can
somebody help me with the code?

Also I'd like to know if - after the new workbook is saved - there is a way
to revert to the original workbook, delete different rows from the worksheet
and then save it again with the original workbooks name and " - student2". Is
this possible?

Any help apriciated.

Steven.
 
Untested.

Dim iPos As Long
Dim sFilename As String
Dim sFilenum As String
Dim iFilenum As Long

sFilename = ActiveWorkbook.Name
iPos = InStr(sFilename, "-")
If Mid(sFilename, iPos + 2, 7) = "student" Then
sFilenum = Mid(sFilename, iPos + 9, Len(sFilename) - iPos - 8)
If IsNumeric(sFilenum) Then
iFilenum = CLng(sFilenum) + 1
sFilename = Left(sFilename, iPos + 8) & iFilenum
Else
sFilename = sFilename & " - student1"
End If
Else
sFilename = sFilename & " - student1"
End If
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "\" & sFilename


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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