Solved

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

Posted on 2006-07-20
9
496 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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
 

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

Increase your protection from Zero Day threats!

Running two Antivirus' is never a good idea.
Taking advantage of Multiple Security layers on the other hand can often save your hide.
See which top notch security software brands have been proven to happily coexist together.
Reduce your chances of becoming a statistic.

Question has a verified solution.

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

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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