Compile error: Object required

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?
 
B

brookh

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
 
M

Michael Bauer [MVP - Outlook]

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:
 

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