Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

setting the name in a workbook

  Asked By: Glenn    Date: Aug 25    Category: MS Office    Views: 771
  

I'm new to excel and vba so I appologize it this question is out of
scope.

The code below creates a workbook, names it and saves it.

Set newWB = Workbooks.Add
With newWB
.Title = "Yield Curves"
.Subject = "Yield Curves"
.SaveAs Filename:="c:\foo.xls"
End With

What I would like to do is create a workbook and name it. I do NOT want
to save it. I haven't been able to find a way to do this. Is this
possible? If so how?

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Kanchan Ap     Answered On: Aug 25

what are you trying to do? if you don't want to save  it.. why do you need
to name it?

 
Answer #2    Answered By: Haya Yoshida     Answered On: Aug 25

You are possibly getting misled by the "with" statement. Your code  is
equivalent to

> Set newWB = Workbooks.Add
> WB.Title = "Yield Curves"
> WB.Subject = "Yield Curves"
> Call WB.SaveAs(Filename:="c:\foo.xls")

which is more specific (and two lines shorter),

The important thing to note is that there are actually four separate
statements here, not one multi-line call with several parameters.

If you don't want to save  the file, just remove the SaveAs call.

You do say "create a workbook  and name it". Workbooks are files. They
don't have separate names  - they use the files' names. So, it won't have a
name other than "Book1" until it's saved. (This is similar to other
programs that have a File/New facility - like Word, NotePad, etc.)

 
Answer #3    Answered By: Geneva Morris     Answered On: Aug 25

Looks like the "New" threw you. It is not a keyword, but part of the name.



The code  should be

newWB.Title = "Yield Curves"

newWB.Subject = "Yield Curve"

Call newWB.SaveAS(Filename:="c:\foo.xls")

 
Answer #4    Answered By: Fabia Ferrrari     Answered On: Aug 25

Very true, thanks. I've been writing mostly Java for the last several
months and "new" is always a keyword there, so I didn't notice it here.

 
Didn't find what you were looking for? Find more on setting the name in a workbook Or get search suggestion and latest updates.




Tagged: