Code to add a workbook the rename it

  • Thread starter Thread starter L. Howard Kittle
  • Start date Start date
L

L. Howard Kittle

Hi Excel users and experts

Excel 2002

From help I get the following to name a workbook. It errors out with a
yellow line. I tried the macro recorder but it give the file name and a
whole string of stuff I don't want using Save As.

Am I missing a menu item that will allow me to record a workbook name
change??? (The AutoFit is just part of the code to format a sheet)

Columns("A:K").Columns.AutoFit
Workbook.Names.Add Name:="The Newest"

Thanks,
Howard
 
What you got from the macro recorder is going to be closer to what you want.
You can not just change the name of a file. You need to save it. The first
time you save something it is by default a save as operation...

dim wbkNew as workbook

set wbknew = workbooks.add
with wbknew
.saveas "C:\Myfile.xls"
.close 'or whatever you want to do with then new book
end with
 
This is from the VBA help file:

The Name property returns the workbook name. You cannot set the name by
using this property; if you need to change the name, use the SaveAs method to
save the workbook under a different name.
 
Thanks Jim and JL, that sheds some light on it.

Regards,
Howard
 

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