Can't name new workbook

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.
 
R

Rick Rothstein

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".
 

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

Top