Workbook.add

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,565
Hi

Why the code below is acceptable?

Workbooks.Add.SaveAs Filename:="c:\testing.xlsx"

The part I do not understand, is that Add is a method so why excel accept

Add.SaveAs?

The above code, means Add is an object. So I checked Add and it is method that return Workbook as a type. A function return an object? That is confusing? any help how to understand that line of code? Thank you very much
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,779
The .Add function of the workbooks object returns a workbook object (the new workbook)

Workbooks.Add.SaveAs applies the .SaveAs method to that newly created workbook.

The code in the OP is the same as this

Code:
Dim wb as Workbook

Set  wb = Workbooks.Add

wb.SaveAs Filename:="c:\testing.xlsx"
 

Watch MrExcel Video

Forum statistics

Threads
1,109,001
Messages
5,526,203
Members
409,686
Latest member
Tori83

This Week's Hot Topics

Top