Solved

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

Posted on 2006-07-20
9
479 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:
smozgur 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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

Expert Comment

by:smozgur
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

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.

Join & Write a Comment

Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
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 …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

757 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

21 Experts available now in Live!

Get 1:1 Help Now