What is Attributes and WithEvents???

M

masani paresh

Hi All,

Could anyone please help me to understand below code. It shows me systax
error when I copy paste in ThisOutlookSession in my outlook.

VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
End
VB_Name = "ThisOutlookSession"
VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
Public WithEvents colExplorers As Outlook.Explorers
Attribute colExplorers.VB_VarHelpID = -1
Public WithEvents objExplorer As Outlook.Explorer
Attribute objExplorer.VB_VarHelpID = -1
 
K

Ken Slovak - [MVP - Outlook]

Well, for one thing BEGIN...END blocks aren't VBA code, so I'd expect
errors. That looks like some Pascal or Delphi type code. VERSION also isn't
VBA code.

None of the variables is declared as to type, which will make them all
Variants if Option Explicit is off, with that option on there are more
errors.

Attribute is also not VBA code, unless it's qualified as to what it refers
to.

WithEvents is VBA/VB for declaring an object that handles events and makes
those events accessible to you code.

That looks like some weird mix of VBA and Delphi or Pascal code to me. I'd
expect lots of errors.
 
S

Sue Mosher [MVP-Outlook]

Actually, it looks like what you get if you export the ThisOutlookSession
module from VBA to a .cls file and then open that .cls file in Notepad. It
should be possible to import the file into VBA and then see the imported code
in the new class module that the import creates.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54




Ken Slovak - said:
Well, for one thing BEGIN...END blocks aren't VBA code, so I'd expect
errors. That looks like some Pascal or Delphi type code. VERSION also isn't
VBA code.

None of the variables is declared as to type, which will make them all
Variants if Option Explicit is off, with that option on there are more
errors.

Attribute is also not VBA code, unless it's qualified as to what it refers
to.

WithEvents is VBA/VB for declaring an object that handles events and makes
those events accessible to you code.

That looks like some weird mix of VBA and Delphi or Pascal code to me. I'd
expect lots of errors.
 
M

masani paresh

Perferctly correct Sue. You are really great. I have purchased your two books
on Configuration Outlook 2003 and Microsof Outlook 2007 programming. Its
awesome.

We have been facing so many problems in free/busy information while booking
conference through outlook. Actually problem is free/busy status is not
getting updated immediately once user booked the conference room and mean
while some other user select the same conference as he can see the free
status.

If you have any ideas on this issue or your any of book talk about this then
please let me know. Actually I purchase Configuring Microsoft Outlook for
this issue but it didn't help much.

--
Thanks,
Paresh


Sue Mosher said:
Actually, it looks like what you get if you export the ThisOutlookSession
module from VBA to a .cls file and then open that .cls file in Notepad. It
should be possible to import the file into VBA and then see the imported code
in the new class module that the import creates.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
M

masani paresh

Thanks Ken for you reply.
--
Thanks,
Paresh


Ken Slovak - said:
Well, for one thing BEGIN...END blocks aren't VBA code, so I'd expect
errors. That looks like some Pascal or Delphi type code. VERSION also isn't
VBA code.

None of the variables is declared as to type, which will make them all
Variants if Option Explicit is off, with that option on there are more
errors.

Attribute is also not VBA code, unless it's qualified as to what it refers
to.

WithEvents is VBA/VB for declaring an object that handles events and makes
those events accessible to you code.

That looks like some weird mix of VBA and Delphi or Pascal code to me. I'd
expect lots of errors.
 
Joined
Nov 13, 2013
Messages
1
Reaction score
0
An old thread, but I wanted to fill in on it anyway...

The attributes you see (and the BEGIN/END) are part of the VB language, but not exposed directly in VBA. As Sue says, they're visible when you export a module, and they DO take effect based on their respective settings when imported to a project. It is someone common (among Access developers, at least) to export a module so that these attributes can be modified, and import the module back into the project again.

VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
End​
So far as I'm aware, this is part of every class module and will always look the same.

VB_Name = "ThisOutlookSession"​
The name of the module as it loads when imported (filename is irrelevant)

VB_GlobalNameSpace = False​
This one I'm unfamiliar with...

Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True​
These three deal with how the class is seen from outside the project - whether it can be used external, whether it can be created externally, etc. Specific details escape me, having no reference in front of me on them at the moment, though. (go to UtterAccess.com and search in the Wiki there for an article called Singleton, which gives one such example).


Public WithEvents colExplorers As Outlook.Explorers
Attribute colExplorers.VB_VarHelpID = -1
Public WithEvents objExplorer As Outlook.Explorer
Attribute objExplorer.VB_VarHelpID = -1​
The VarHelpID is an internal note for linking the line with a help context in the object browser. Apparently, there's even ways to pull up custom help files for custom objects in the Object Browser using similar syntaxes, though I have no personal experience with this.


There's a handful more that aren't shown here - for example, we can write a custom collection object, export it, set the default item and enumerable, then re-import, thus allowing us to use a custom collection class in a for each ... next loop.

Anyway, just figured I'd clear some of that up in case others come across this. They're there for a reason and they have an effect on how the code works, thus I'd advise tweaking them unless you know what they're doing and what you intend to do.

Jack D. Leach
Microsoft Access MVP
dymeng.com
 

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