Workbooks.Add question

B

Barb Reinhardt

I have the following line of code in a workbook that I'm working on.

Workbooks.Add ThisWorkbook.Path + "\" + "MyTempWrkSht.xls"

when I get to this line, it opens the workbook that's listed. I thought
Workbooks.Add created a new workbook. Can someone please help me with my
confusion.

Thanks,
Barb Reinhardt
 
R

Rick Rothstein

According the the help files, the Add Method for a Workbook Object...

"Creates a new workbook. The new workbook becomes the active workbook."
 
P

Peter T

I thought
Workbooks.Add created a new workbook.

It does. If you add a valid filename that'll open as a template.

In passing, although + works to concatenate strings best to use &. In some
scenarios not the same.


Regards,
Peter T
 
C

Chip Pearson

The Add method takes as an optional parameter a Template file name. If
this is supplied, it uses that file as a template. For example,

Workbooks.Add
just opens a new workbook (based on Book.xlt if that exists in the
XLStart directory).

Workbooks.Add "C:\Book1.xls"
opens a new workbook based on C:\Book1.xls. You'll notice that a "1"
is appended to the file name, so the file open in Excel would be
C:\Book11.xls.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

On Thu, 19 Mar 2009 12:24:00 -0700, Barb Reinhardt <Barb
 
D

Dave Peterson

Just a typo...

The workbook that was created wouldn't have the extension (or path). It would
just be named:

Book11
 
C

Chip Pearson

As usual, you're right.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
D

Dave Peterson

I'll take the easy questions!

Chip said:
As usual, you're right.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

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