Avatar of Robert Berke
Robert Berke
Flag for United States of America

asked on 

Correct terminology for VBA Dim var As xxxxx.yyyyy. What is xxxxx and yyyyy?

 
This is a question about the  terminology for “Dim var as  xxxxx.yyyyy “.  
 
For many years I loosely used terms like Library, Class, Type. But I am now trying to be more precise and find that I am confused.
For example: The following line defines an object with type Shellwindows from the ShDocVw Library,  
 
Dim var2 As New SHDocVw.ShellWindows
 
So it would appear that the general syntax is simple:
                Dim var As Library.Type
 
But I attach an image with a green circle that makes me wonder if the syntax is  
Dim var As Library.Class.
 
And eventually (but not now) I may ask a related question about CreateObject(class, [ servername ])
 
The image shows the following for Shellwindows.
 
 
    Class ShellWindows
    Member of SHDocVw     
    ShellDispatch Load in Shell Context
 
    Library SHDocVw
    C:\Windows\SysWOW64\ieframe.dll
    Microsoft Internet Controls
 
IN OTHER WORDS ShellWindows is a Class that is the member of the SHDocVw library which is from ieframe.dll

What it the correct terminology?
 
 
Microsoft documentation is not simple.  
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/dim-statement syntax shows.  
 
Dim [ WithEvents ] varname [ ( [ subscripts ] ) ] [ As [ New ] type ] [ , [ WithEvents ] varname [ ( [ subscripts ] ) ] [ As [ New ] type ]] .
 
Where type is  Byte ,..etc… or an object type.
 
And Object type is: “A type of object exposed by an application through Automation, for example, Application, File, Range, and Sheet. Use the Object Browser or refer to the application's documentation for a complete listing of available objects.”
 
Clear as mud!
 
 
And here are several variable types that might be worth discussing
 
 
dim var0 as object
set var0 =  createobject ("Excel.Application")  ' vba help says syntax is CreateObject(class, [ servername ])
 
Dim var1 As New Scripting.Dictionary
Dim var2 As New SHDocVw.ShellWindows
Dim var3 As New Dao.Recordset
Dim var4 As New Scripting.FileSystemObject
Dim var5 As New Scripting.Folder
dim var6 As New Dataobject
dim var7 as New Excel.Application
 
 
Microsoft OfficeVBA* Object Oriented Programming

Avatar of undefined
Last Comment
Robert Berke

8/22/2022 - Mon