In VBA procedures we are constantly meeting the keyword New usually on instantiation of an object reference to an existing object instance. But in some instantiations we use the keyword New while in others we don't for example:
Dim T As Excel.Workbook
Set T = Application.Workbooks(Bk)
In the upper example No.1 the "New" keyword has not been used
Dim fso As FileSystemObject
Set fso = New FileSystemObject
In the upper example No.2 the New keyword is being used
Why that? Keep in mind i'm fresh of the boat in VBA but i will do my best to understand!
In addition to that i also get confused when is used/not-used in declaring an object reference for example:
Dim WS As Worksheet
In the upper example No.1 the "New" keyword has not been used
Dim myClassModule As New cl_ChartEvents
In the upper example No.2 the New keyword is being used
The Microsoft Help just tells me nothing...
Keyword that enables implicit creation of an object. If you use New when declaring the object variable, a new instance of the object is created on first reference to it, so you don't have to use the Set statement to assign the object reference.
Gratz2u
Dear people just a last dust-off for deep understanding
Dim WS as Worksheet
Set WS = Worksheets("Sheet1")
Right here we are creating an object that already existed in order to open MS Excel (lets say for examples sake in "default mode") of course which is Sheet1. Since it exists and the New
keyword is out of the question how could we instantiate this object in one line right away?
4 @exantas
Sorry says not enough rep to post pic :-(
See Question&Answers more detail:os