Change subject vb.net

P

peter.sitskoorn

Hi,
I want to change to change the subject of a message in Outlook. For
that I have create some code to do so in .net. However, when I press
the button, nothing happens. I only get the bloody msgbox (it does
something, but not what I want...). Does anybody has any suggestions
how to get it working?

Here's the code:

Private Sub MyButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles MyButton.Click

Dim objOL As Outlook.Application
Dim objMsg As Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim NewSubject As String
Dim olMail As Outlook.MailItem
On Error Resume Next

' Instantiate an Outlook Application object.
objOL = CreateObject("Outlook.Application")
' Get the collection of selected objects.
objSelection = objOL.ActiveExplorer.Selection

For Each objMsg In objSelection
'select the message and ask for a new subject, then save
If objMsg.Class Is olMail Then
NewSubject = InputBox("Geef het onderwerp van het
bericht", "Enter Subject", objMsg.Subject)
objMsg.Subject = NewSubject
objMsg.Save()
Else
End If
Next

'release objects
objMsg = Nothing
objSelection = Nothing
objOL = Nothing

MsgBox("Our CommandBar button was pressed, and the code has
ended!")

End Sub

Thanks
Peter
 
D

Dmitry Streblechenko

Change the line
If objMsg.Class Is olMail Then
to
If objMsg.Class = olMail Then

You might also want to check whether there is an active explorer
(objOL.ActiveExplorer is Nothing).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
X

XPete

Thanks Dmitry, you inspired me to get rid of the complete if statement.
I removed it and now it works!

Thanks again,
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top