Graham Charles
Posts: 13
Joined: 2005-07-29
|
I've got an event handler that enables a button based on whether a MailItem is selected in an explorer in Outlook:
Private Sub adxOutlookEvents_ExplorerSelectionChange(ByVal sender As Object, ByVal explorer As Object) Handles adxOutlookEvents.ExplorerSelectionChange
On Error GoTo errhandler
If explorer.Selection.Count = 1 Then
If TypeName(explorer.selection.item(1)) = "MailItem" Then
btnCategorizeSender.Enabled = True
Else
btnCategorizeSender.Enabled = False
End If
End If
ExitHere:
Exit Sub
ErrHandler:
' TODO: log error
Resume ExitHere
End Sub
Unfortunately, it doesn't work. Even after the line
btnCategorizeSender.Enabled = True
the property still returns false. It appears that "Enabled" is a read-only property.
Any ideas?
Thanks,
g. |
|
mdriver
Guest
|
Hi
I Disable/Enable buttons based on properties of e-mail in explorer myself. I actually use something like this:
I first test the typeName of the explorer Outlook sometimes returns "Nothing" so I exit my code so I don't get an error:
If TypeName(explorer) <> "nothing" Then
exit
else
'Test to see if actually an e-mail
If (explorer.Class <> 34) Then
exit
else
'If user selects Outlook box do nothing as item is being sent
If explorer.CurrentFolder.Name = "Outbox" Then
exit
else
'Ensure only one e-mail selected
If explorer.CurrentFolder.Items.Count <> 1 Then
exit
else
'Test if selection is actually something
Dim selection As Outlook.Selection = Nothing
selection = explorer.Selection
If (selection Is Nothing) Then
exit
else
'Now get a Object refernce to the current Selection
Dim object_ As Object
object_ = selection.Item(1)
If (object_ Is Nothing) Then
exit
else
Now get a reference to the MailItem
If object_.Class <> Outlook.OlObjectClass.olMail Then
Dim item As MailItem
item = object_
If item_Sent = False Then
'We have a unsent e-mail
else
'We have a sent e-mail
end if
So basically I exit the event if the current explorer selected item is not a single mail item. I also show how to handle if the item is unsent or sent.
I hope some of this this helps and you can convert it into working code.
This is my own view and not the view or suppported by Afalinasoft.
Regards
Matt
|
|
mdriver
Guest
|
Forgot to add I then disable/enable buttons using:
If AdxCmdBarBtn_Refresh_EX.Visible = False Then
AdxCmdBarBtn_Refresh_EX.Visible = True
End If
If AdxCmdBarBtn_Export_EX.Enabled = True Then
AdxCmdBarBtn_Export_EX.Enabled = False
End If
Let me know if you are still having trouble.
Matt |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
|