Solved

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

Posted on 2006-07-20
9
482 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Read this checklist to learn more about the 15 things you should never include in an email signature.
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

810 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