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

proltdman
proltdman used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006

Commented:
hi
read this article
it will help u in solving the problem

http://support.microsoft.com/default.aspx/kb/250309
Top Expert 2006

Commented:
let us know if u have any problem

Author

Commented:
Thanks but sorry this solution did not help me resolve the issue, anyone else out there with another idea?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Web / Application Developer
Commented:
Hi,

Try using :

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

instead in line 5 in your code.

Suat

Author

Commented:
Thanks smozgur, your solution did the trick!
Suat OzgurWeb / Application Developer

Commented:
Glad to hear that!

Thanks for the A grade.
Suat
Top Expert 2010

Commented:
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.  

Author

Commented:
thanks for the explanation BDF!
Top Expert 2010

Commented:
:-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial