Can't name new workbook

  • Thread starter Thread starter salgud
  • Start date Start date
S

salgud

Is it possible to name a new workbook in VBA? I keep trying to, and get a
message that workbook.name is ready-only. If it's read-only, does that mean
you can't name a workbook in VBA? I thought I had a long time ago, but I
can't find the code in my library. Confused.

wbNew.name = "Ted" <---Compile error. Can't assign to read-only property.
 
Yep, that is what the help files say. The workbook's name is its filename on
the hard disk, so you have to execute code that will change its name there.
If the workbook is open, you should be able to use the SaveAs method like
Barb posted. If it is not open, the you can rename the file on the disk
using VB's Name..As statement. For example...

Name "C:\Users\Rick\Documents\NewBook.xls" As
"C:\Users\Rick\Documents\Ted.xls"

assuming its current name is "NewBook".
 
Back
Top