Create New WB, Not Read Only

  • Thread starter Thread starter Otto Moehrbach
  • Start date Start date
O

Otto Moehrbach

Excel 2002, WinXP
The code:

Sub Test
ActiveSheet.Copy
ActiveWorkbook.Name = NewName
End Sub

Creates a new workbook with the above active sheet. I want to name the new
workbook the variable NewName but the code:
ActiveWorkbook.Name = NewName
produces an error because the file is Read Only.
How can I change the Read Only attribute of the new file so that I can
change its name?
Thanks for your help. Otto
 
Sub Test
sPath = Activeworkbook.Path
if Right(sPath,1) <> "\" then sPath = sPath & "\"
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:= sPath & NewName & ".xls"
End Sub

The name of a workbook is its filename.
 
Thanks Tom. That's clear and concise. Otto
Tom Ogilvy said:
Sub Test
sPath = Activeworkbook.Path
if Right(sPath,1) <> "\" then sPath = sPath & "\"
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:= sPath & NewName & ".xls"
End Sub

The name of a workbook is its filename.
 

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