Solved

Run-time error '91' Object variable or with block variable not set in outlook 2003

Posted on 2006-07-20
9
480 Views
Last Modified: 2008-01-09
I am trying to run a macro in outlook 2003 and I am getting the error above, any help would be appreciated.

the macro is shown below:

Sub type1()
    Dim strMessage, olkItem, olkReply, olkInbox, olkNewFolder
    strMessage = "Thank you for forwarding your CV which we have received. We look forward to working with you."

    Set olkItem = Application.ActiveInspector.CurrentItem
    Set olkReply = olkItem.Reply
    With olkReply
        .Subject = "Confirmation of receipt"
        .Body = strMessage
        .Send
    End With
    On Error Resume Next
    Set olkInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
    Set olkNewFolder = olkInbox.Folders.Add("Type 1")
    Set olkNewFolder = olkInbox.Folders("Type 1")
    If olkNewFolder Is Nothing Then
    Set olkNewFolder = olkInbox.Folders.Add("Type 1")
    End If
    Set olkForward = olkItem.Forward
    olkForward.Recipients.Add "email@email.com"
    olkForward.Send
    olkItem.Move olkNewFolder
    On Error GoTo 0
End Sub
0
Comment
Question by:proltdman
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 17145195
hi
read this article
it will help u in solving the problem

http://support.microsoft.com/default.aspx/kb/250309
0
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 17145197
let us know if u have any problem
0
 

Author Comment

by:proltdman
ID: 17145279
Thanks but sorry this solution did not help me resolve the issue, anyone else out there with another idea?
0
 
LVL 17

Accepted Solution

by:
Suat Ozgur earned 250 total points
ID: 17145353
Hi,

Try using :

    Set olkItem = Application.ActiveExplorer.Selection.Item(1)

instead in line 5 in your code.

Suat
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

Author Comment

by:proltdman
ID: 17145423
Thanks smozgur, your solution did the trick!
0
 
LVL 17

Expert Comment

by:Suat Ozgur
ID: 17145438
Glad to hear that!

Thanks for the A grade.
Suat
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17153389
Just to explain a bit about why this problem cropped up, the original line of code

    Set olkItem = Application.ActiveInspector.CurrentItem

gets the open item.  You were getting an error because there was no open item.  The line of code

    Set olkItem = Application.ActiveExplorer.Selection.Item(1)

that smozgur had you use in its place gets the selected item instead of the open item.  
0
 

Author Comment

by:proltdman
ID: 17153398
thanks for the explanation BDF!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17157289
:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now