Compile error: Object required

  • Thread starter Thread starter brookh
  • Start date Start date
B

brookh

I'm trying to write a macro for Outlook 2007, and getting nonsensical compile
errors. For example: The following script results in "Compile error: Object
required"

Sub TestScript()
Dim x As Integer
Set x = 2
End Sub

Am I doing something wrong or is my Outlook VBA just broken?
 
The "object required" error refers to the "Set" statement, which is only used
for assigning objects. When assigning simple variables, do not use "Set". The
correct code is:

Sub TestScript()
Dim x As Integer
' Set x = 2 results in "Compiler error: Object required"
x = 2
End Sub
 
The Set statement is used only for object variables; but you have declared x
as Integer, so x=2 would do it.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Sat, 13 Jun 2009 10:36:01 -0700 schrieb brookh:
 
Back
Top