Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Change Workbook's Name

  Asked By: Raynard    Date: Nov 14    Category: MS Office    Views: 1013
  

I have a simple question. I want to create a new workbook with
name "abc".
so I write the VBA code:

sub cmdCreateNew ()
Workbooks.Add
ActiveWorkbook.Name="abc"
end sub

but the VBA said Name property is read only.
I am new with VBA, any one can tell me how can I change the workbook's
name?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Muhammad Evans     Answered On: Nov 14

OK. The Name is the file name so just save it and it will get a name.

 
Answer #2    Answered By: Kian Evans     Answered On: Nov 14

if you want to do it from vba  then you would add a line after the
workbooks.add or change  the next line to

Activeworkbook.saveas FileName:="abc"

 
Answer #3    Answered By: Tomas Thompson     Answered On: Nov 14

This technique is VERY useful in determining how Excel does things.
First, record a macro. ( would suggest having it stored in your Personal
workbook for now).
Then, using the standard excel menus, choose File -> Save As
Change the path to where you want to store the file, and enter the file name.
hit the return (or "save" button).
Stop recording.

Then, go to your VBA editor, select your Personal workbook  (or whereever you
told it to store it) and look at the code  for your macro.
This will give you the command syntax that Excel used to create  your file.

 
Didn't find what you were looking for? Find more on Change Workbook's Name Or get search suggestion and latest updates.




Tagged: