A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Tags: , , , ,

Adding a 2nd button (functionality not working)





 
 
Thread Tools Display Modes
  #1  
Old March 3rd 06, 07:44 PM posted to microsoft.public.outlook.program_vba
Newt
external usenet poster
 
Posts: 6
Default Adding a 2nd button (functionality not working)

I'm a hack at writing this code, but here goes. I added a toggle button
several months ago that works great for adding Read Receipts. Now, I'd like
to add another button that allows me to select whether I save a copy in the
Sent Items folder. I figured out the correct code for one button, but don't
know how to make it work so that both buttons function together. Any help?

'THIS OUTLOOK SESSION
Private WithEvents m_oInspector As Outlook.Inspector
Private WithEvents m_oMailItem As Outlook.MailItem
Private WithEvents YourButton As Office.CommandBarButton
Private WithEvents YourButton1 As Office.CommandBarButton
Private m_lKey As Long

Friend Function Init(oInspector As Outlook.Inspector, ByVal lKey As Long) As
Boolean
Set m_oInspector = oInspector
Set m_oMailItem = oInspector.CurrentItem
If m_oMailItem.Sent = False Then
m_lKey = lKey
CreateButton oInspector
CreateButton1 oInspector
Init = True
End If
End Function

Private Sub CreateButton(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars
Dim objPicture As stdole.IPictureDisp
Dim objMask As stdole.IPictureDisp

Const PICTURE_PATH As String = "C:\Documents and
Settings\drhyase\Icons\readreceipt.bmp"
Const PICTURE_MASK As String = "C:\Documents and
Settings\drhyase\Icons\readreceiptmask.bmp"

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton = colCBcontrols.Add(msoControlButton, , "Standard", ,
True)
Set objPicture = LoadPicture(PICTURE_PATH)
Set objMask = LoadPicture(PICTURE_MASK)
With YourButton
.Caption = "&Read Receipt"
.Move Befo=3
.TooltipText = "Add/Remove a Read Receipt"
.Picture = objPicture
.Mask = objMask
.Style = msoButtonIconAndCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub
Private Sub CreateButton1(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton1 = colCBcontrols.Add(msoControlButton, , "Standard",
, True)

With YourButton1
.Caption = "Save Copy"
.Move Befo=4
.TooltipText = "Save in Sent Items Folder"
.Style = msoButtonCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub

Friend Sub CloseInspector()
On Error Resume Next
Application.RemoveInspector m_lKey
Set YourButton = Nothing
Set YourButton1 = Nothing
Set m_oMailItem = Nothing
Set m_oInspector = Nothing
End Sub

Private Sub m_oInspector_Close()
CloseInspector
End Sub

Private Sub m_oMailItem_Close(Cancel As Boolean)
If m_oMailItem.Saved Then
CloseInspector
End If
End Sub

Private Sub m_oMailItem_Send(Cancel As Boolean)
CloseInspector
End Sub
Private Sub YourButton_Click1(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp1 As Outlook.Inspector
Dim objItem1 As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp1 = Application.ActiveInspector
If Not objInsp1 Is Nothing Then
Set objItem1 = objInsp1.CurrentItem
If objItem1.Class = olMail Then
' make sure it's unsent
If objItem1.Sent = False Then
' button action on
If YourButton1.State = msoButtonUp Then
YourButton1.State = msoButtonDown
Else
YourButton1.State = msoButtonUp
End If
If objItem1.DeleteAfterSubmit = False Then
objItem1.DeleteAfterSubmit = True
' button action off
Else
objItem1.DeleteAfterSubmit = False
End If
End If
End If
End If

Set objInsp1 = Nothing
Set objItem1 = Nothing

End Sub

Private Sub YourButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp As Outlook.Inspector
Dim objItem As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp = Application.ActiveInspector
If Not objInsp Is Nothing Then
Set objItem = objInsp.CurrentItem
If objItem.Class = olMail Then
' make sure it's unsent
If objItem.Sent = False Then
' button action on
If YourButton.State = msoButtonUp Then
YourButton.State = msoButtonDown
Else
YourButton.State = msoButtonUp
End If
If objItem.ReadReceiptRequested = False Then
objItem.ReadReceiptRequested = True
' button action off
Else
objItem.ReadReceiptRequested = False
End If
End If
End If
End If

Set objInsp = Nothing
Set objItem = Nothing

End Sub

'CLASS MODULE (cInspector)
Private WithEvents m_oInspector As Outlook.Inspector
Private WithEvents m_oMailItem As Outlook.MailItem
Private WithEvents YourButton As Office.CommandBarButton
Private WithEvents YourButton1 As Office.CommandBarButton
Private m_lKey As Long

Friend Function Init(oInspector As Outlook.Inspector, ByVal lKey As Long) As
Boolean
Set m_oInspector = oInspector
Set m_oMailItem = oInspector.CurrentItem
If m_oMailItem.Sent = False Then
m_lKey = lKey
CreateButton oInspector
CreateButton1 oInspector
Init = True
End If
End Function

Private Sub CreateButton(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars
Dim objPicture As stdole.IPictureDisp
Dim objMask As stdole.IPictureDisp

Const PICTURE_PATH As String = "C:\Documents and
Settings\drhyase\Icons\readreceipt.bmp"
Const PICTURE_MASK As String = "C:\Documents and
Settings\drhyase\Icons\readreceiptmask.bmp"

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton = colCBcontrols.Add(msoControlButton, , "Standard", ,
True)
Set objPicture = LoadPicture(PICTURE_PATH)
Set objMask = LoadPicture(PICTURE_MASK)
With YourButton
.Caption = "&Read Receipt"
.Move Befo=3
.TooltipText = "Add/Remove a Read Receipt"
.Picture = objPicture
.Mask = objMask
.Style = msoButtonIconAndCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub
Private Sub CreateButton1(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton1 = colCBcontrols.Add(msoControlButton, , "Standard",
, True)

With YourButton1
.Caption = "Save Copy"
.Move Befo=4
.TooltipText = "Save in Sent Items Folder"
.Style = msoButtonCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub

Friend Sub CloseInspector()
On Error Resume Next
Application.RemoveInspector m_lKey
Set YourButton = Nothing
Set YourButton1 = Nothing
Set m_oMailItem = Nothing
Set m_oInspector = Nothing
End Sub

Private Sub m_oInspector_Close()
CloseInspector
End Sub

Private Sub m_oMailItem_Close(Cancel As Boolean)
If m_oMailItem.Saved Then
CloseInspector
End If
End Sub

Private Sub m_oMailItem_Send(Cancel As Boolean)
CloseInspector
End Sub
Private Sub YourButton_Click1(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp1 As Outlook.Inspector
Dim objItem1 As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp1 = Application.ActiveInspector
If Not objInsp1 Is Nothing Then
Set objItem1 = objInsp1.CurrentItem
If objItem1.Class = olMail Then
' make sure it's unsent
If objItem1.Sent = False Then
' button action on
If YourButton1.State = msoButtonUp Then
YourButton1.State = msoButtonDown
Else
YourButton1.State = msoButtonUp
End If
If objItem1.DeleteAfterSubmit = False Then
objItem1.DeleteAfterSubmit = True
' button action off
Else
objItem1.DeleteAfterSubmit = False
End If
End If
End If
End If

Set objInsp1 = Nothing
Set objItem1 = Nothing

End Sub

Private Sub YourButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp As Outlook.Inspector
Dim objItem As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp = Application.ActiveInspector
If Not objInsp Is Nothing Then
Set objItem = objInsp.CurrentItem
If objItem.Class = olMail Then
' make sure it's unsent
If objItem.Sent = False Then
' button action on
If YourButton.State = msoButtonUp Then
YourButton.State = msoButtonDown
Else
YourButton.State = msoButtonUp
End If
If objItem.ReadReceiptRequested = False Then
objItem.ReadReceiptRequested = True
' button action off
Else
objItem.ReadReceiptRequested = False
End If
End If
End If
End If

Set objInsp = Nothing
Set objItem = Nothing

End Sub


Ads
  #2  
Old March 3rd 06, 09:38 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 817
Default Adding a 2nd button (functionality not working)

What exactly do you mean? Do you want both functions - one to request a
receipt and the other to toggle saving a copy - to fire by one button? Or
are you just having troubleh having a second button do anything?

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Newt" wrote:

I'm a hack at writing this code, but here goes. I added a toggle button
several months ago that works great for adding Read Receipts. Now, I'd like
to add another button that allows me to select whether I save a copy in the
Sent Items folder. I figured out the correct code for one button, but don't
know how to make it work so that both buttons function together. Any help?

'THIS OUTLOOK SESSION
Private WithEvents m_oInspector As Outlook.Inspector
Private WithEvents m_oMailItem As Outlook.MailItem
Private WithEvents YourButton As Office.CommandBarButton
Private WithEvents YourButton1 As Office.CommandBarButton
Private m_lKey As Long

Friend Function Init(oInspector As Outlook.Inspector, ByVal lKey As Long) As
Boolean
Set m_oInspector = oInspector
Set m_oMailItem = oInspector.CurrentItem
If m_oMailItem.Sent = False Then
m_lKey = lKey
CreateButton oInspector
CreateButton1 oInspector
Init = True
End If
End Function

Private Sub CreateButton(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars
Dim objPicture As stdole.IPictureDisp
Dim objMask As stdole.IPictureDisp

Const PICTURE_PATH As String = "C:\Documents and
Settings\drhyase\Icons\readreceipt.bmp"
Const PICTURE_MASK As String = "C:\Documents and
Settings\drhyase\Icons\readreceiptmask.bmp"

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton = colCBcontrols.Add(msoControlButton, , "Standard", ,
True)
Set objPicture = LoadPicture(PICTURE_PATH)
Set objMask = LoadPicture(PICTURE_MASK)
With YourButton
.Caption = "&Read Receipt"
.Move Befo=3
.TooltipText = "Add/Remove a Read Receipt"
.Picture = objPicture
.Mask = objMask
.Style = msoButtonIconAndCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub
Private Sub CreateButton1(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton1 = colCBcontrols.Add(msoControlButton, , "Standard",
, True)

With YourButton1
.Caption = "Save Copy"
.Move Befo=4
.TooltipText = "Save in Sent Items Folder"
.Style = msoButtonCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub

Friend Sub CloseInspector()
On Error Resume Next
Application.RemoveInspector m_lKey
Set YourButton = Nothing
Set YourButton1 = Nothing
Set m_oMailItem = Nothing
Set m_oInspector = Nothing
End Sub

Private Sub m_oInspector_Close()
CloseInspector
End Sub

Private Sub m_oMailItem_Close(Cancel As Boolean)
If m_oMailItem.Saved Then
CloseInspector
End If
End Sub

Private Sub m_oMailItem_Send(Cancel As Boolean)
CloseInspector
End Sub
Private Sub YourButton_Click1(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp1 As Outlook.Inspector
Dim objItem1 As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp1 = Application.ActiveInspector
If Not objInsp1 Is Nothing Then
Set objItem1 = objInsp1.CurrentItem
If objItem1.Class = olMail Then
' make sure it's unsent
If objItem1.Sent = False Then
' button action on
If YourButton1.State = msoButtonUp Then
YourButton1.State = msoButtonDown
Else
YourButton1.State = msoButtonUp
End If
If objItem1.DeleteAfterSubmit = False Then
objItem1.DeleteAfterSubmit = True
' button action off
Else
objItem1.DeleteAfterSubmit = False
End If
End If
End If
End If

Set objInsp1 = Nothing
Set objItem1 = Nothing

End Sub

Private Sub YourButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp As Outlook.Inspector
Dim objItem As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp = Application.ActiveInspector
If Not objInsp Is Nothing Then
Set objItem = objInsp.CurrentItem
If objItem.Class = olMail Then
' make sure it's unsent
If objItem.Sent = False Then
' button action on
If YourButton.State = msoButtonUp Then
YourButton.State = msoButtonDown
Else
YourButton.State = msoButtonUp
End If
If objItem.ReadReceiptRequested = False Then
objItem.ReadReceiptRequested = True
' button action off
Else
objItem.ReadReceiptRequested = False
End If
End If
End If
End If

Set objInsp = Nothing
Set objItem = Nothing

End Sub

'CLASS MODULE (cInspector)
Private WithEvents m_oInspector As Outlook.Inspector
Private WithEvents m_oMailItem As Outlook.MailItem
Private WithEvents YourButton As Office.CommandBarButton
Private WithEvents YourButton1 As Office.CommandBarButton
Private m_lKey As Long

Friend Function Init(oInspector As Outlook.Inspector, ByVal lKey As Long) As
Boolean
Set m_oInspector = oInspector
Set m_oMailItem = oInspector.CurrentItem
If m_oMailItem.Sent = False Then
m_lKey = lKey
CreateButton oInspector
CreateButton1 oInspector
Init = True
End If
End Function

Private Sub CreateButton(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars
Dim objPicture As stdole.IPictureDisp
Dim objMask As stdole.IPictureDisp

Const PICTURE_PATH As String = "C:\Documents and
Settings\drhyase\Icons\readreceipt.bmp"
Const PICTURE_MASK As String = "C:\Documents and
Settings\drhyase\Icons\readreceiptmask.bmp"

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton = colCBcontrols.Add(msoControlButton, , "Standard", ,
True)
Set objPicture = LoadPicture(PICTURE_PATH)
Set objMask = LoadPicture(PICTURE_MASK)
With YourButton
.Caption = "&Read Receipt"
.Move Befo=3
.TooltipText = "Add/Remove a Read Receipt"
.Picture = objPicture
.Mask = objMask
.Style = msoButtonIconAndCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub
Private Sub CreateButton1(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton1 = colCBcontrols.Add(msoControlButton, , "Standard",
, True)

With YourButton1
.Caption = "Save Copy"
.Move Befo=4
.TooltipText = "Save in Sent Items Folder"
.Style = msoButtonCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub

Friend Sub CloseInspector()
On Error Resume Next
Application.RemoveInspector m_lKey
Set YourButton = Nothing
Set YourButton1 = Nothing
Set m_oMailItem = Nothing
Set m_oInspector = Nothing
End Sub

Private Sub m_oInspector_Close()
CloseInspector
End Sub

Private Sub m_oMailItem_Close(Cancel As Boolean)
If m_oMailItem.Saved Then
CloseInspector
End If
End Sub

Private Sub m_oMailItem_Send(Cancel As Boolean)
CloseInspector
End Sub
Private Sub YourButton_Click1(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp1 As Outlook.Inspector
Dim objItem1 As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp1 = Application.ActiveInspector
If Not objInsp1 Is Nothing Then
Set objItem1 = objInsp1.CurrentItem
If objItem1.Class = olMail Then
' make sure it's unsent
If objItem1.Sent = False Then
' button action on
If YourButton1.State = msoButtonUp Then
YourButton1.State = msoButtonDown
Else
YourButton1.State = msoButtonUp
End If
If objItem1.DeleteAfterSubmit = False Then
objItem1.DeleteAfterSubmit = True
' button action off
Else
objItem1.DeleteAfterSubmit = False
End If
End If
End If
End If

Set objInsp1 = Nothing
Set objItem1 = Nothing

End Sub

Private Sub YourButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp As Outlook.Inspector

  #3  
Old March 3rd 06, 11:26 PM posted to microsoft.public.outlook.program_vba
Newt
external usenet poster
 
Posts: 6
Default Adding a 2nd button (functionality not working)

I can't get the 2nd button to do anything. I would like 2 buttons--one that
requests read receipts and one that saves a copy. When I put the code in for
both buttons, the "save copy" button doesn't work.

"Eric Legault [MVP - Outlook]" wrote:

What exactly do you mean? Do you want both functions - one to request a
receipt and the other to toggle saving a copy - to fire by one button? Or
are you just having troubleh having a second button do anything?

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Newt" wrote:

I'm a hack at writing this code, but here goes. I added a toggle button
several months ago that works great for adding Read Receipts. Now, I'd like
to add another button that allows me to select whether I save a copy in the
Sent Items folder. I figured out the correct code for one button, but don't
know how to make it work so that both buttons function together. Any help?

'THIS OUTLOOK SESSION
Private WithEvents m_oInspector As Outlook.Inspector
Private WithEvents m_oMailItem As Outlook.MailItem
Private WithEvents YourButton As Office.CommandBarButton
Private WithEvents YourButton1 As Office.CommandBarButton
Private m_lKey As Long

Friend Function Init(oInspector As Outlook.Inspector, ByVal lKey As Long) As
Boolean
Set m_oInspector = oInspector
Set m_oMailItem = oInspector.CurrentItem
If m_oMailItem.Sent = False Then
m_lKey = lKey
CreateButton oInspector
CreateButton1 oInspector
Init = True
End If
End Function

Private Sub CreateButton(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars
Dim objPicture As stdole.IPictureDisp
Dim objMask As stdole.IPictureDisp

Const PICTURE_PATH As String = "C:\Documents and
Settings\drhyase\Icons\readreceipt.bmp"
Const PICTURE_MASK As String = "C:\Documents and
Settings\drhyase\Icons\readreceiptmask.bmp"

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton = colCBcontrols.Add(msoControlButton, , "Standard", ,
True)
Set objPicture = LoadPicture(PICTURE_PATH)
Set objMask = LoadPicture(PICTURE_MASK)
With YourButton
.Caption = "&Read Receipt"
.Move Befo=3
.TooltipText = "Add/Remove a Read Receipt"
.Picture = objPicture
.Mask = objMask
.Style = msoButtonIconAndCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub
Private Sub CreateButton1(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton1 = colCBcontrols.Add(msoControlButton, , "Standard",
, True)

With YourButton1
.Caption = "Save Copy"
.Move Befo=4
.TooltipText = "Save in Sent Items Folder"
.Style = msoButtonCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub

Friend Sub CloseInspector()
On Error Resume Next
Application.RemoveInspector m_lKey
Set YourButton = Nothing
Set YourButton1 = Nothing
Set m_oMailItem = Nothing
Set m_oInspector = Nothing
End Sub

Private Sub m_oInspector_Close()
CloseInspector
End Sub

Private Sub m_oMailItem_Close(Cancel As Boolean)
If m_oMailItem.Saved Then
CloseInspector
End If
End Sub

Private Sub m_oMailItem_Send(Cancel As Boolean)
CloseInspector
End Sub
Private Sub YourButton_Click1(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp1 As Outlook.Inspector
Dim objItem1 As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp1 = Application.ActiveInspector
If Not objInsp1 Is Nothing Then
Set objItem1 = objInsp1.CurrentItem
If objItem1.Class = olMail Then
' make sure it's unsent
If objItem1.Sent = False Then
' button action on
If YourButton1.State = msoButtonUp Then
YourButton1.State = msoButtonDown
Else
YourButton1.State = msoButtonUp
End If
If objItem1.DeleteAfterSubmit = False Then
objItem1.DeleteAfterSubmit = True
' button action off
Else
objItem1.DeleteAfterSubmit = False
End If
End If
End If
End If

Set objInsp1 = Nothing
Set objItem1 = Nothing

End Sub

Private Sub YourButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp As Outlook.Inspector
Dim objItem As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp = Application.ActiveInspector
If Not objInsp Is Nothing Then
Set objItem = objInsp.CurrentItem
If objItem.Class = olMail Then
' make sure it's unsent
If objItem.Sent = False Then
' button action on
If YourButton.State = msoButtonUp Then
YourButton.State = msoButtonDown
Else
YourButton.State = msoButtonUp
End If
If objItem.ReadReceiptRequested = False Then
objItem.ReadReceiptRequested = True
' button action off
Else
objItem.ReadReceiptRequested = False
End If
End If
End If
End If

Set objInsp = Nothing
Set objItem = Nothing

End Sub

'CLASS MODULE (cInspector)
Private WithEvents m_oInspector As Outlook.Inspector
Private WithEvents m_oMailItem As Outlook.MailItem
Private WithEvents YourButton As Office.CommandBarButton
Private WithEvents YourButton1 As Office.CommandBarButton
Private m_lKey As Long

Friend Function Init(oInspector As Outlook.Inspector, ByVal lKey As Long) As
Boolean
Set m_oInspector = oInspector
Set m_oMailItem = oInspector.CurrentItem
If m_oMailItem.Sent = False Then
m_lKey = lKey
CreateButton oInspector
CreateButton1 oInspector
Init = True
End If
End Function

Private Sub CreateButton(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars
Dim objPicture As stdole.IPictureDisp
Dim objMask As stdole.IPictureDisp

Const PICTURE_PATH As String = "C:\Documents and
Settings\drhyase\Icons\readreceipt.bmp"
Const PICTURE_MASK As String = "C:\Documents and
Settings\drhyase\Icons\readreceiptmask.bmp"

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton = colCBcontrols.Add(msoControlButton, , "Standard", ,
True)
Set objPicture = LoadPicture(PICTURE_PATH)
Set objMask = LoadPicture(PICTURE_MASK)
With YourButton
.Caption = "&Read Receipt"
.Move Befo=3
.TooltipText = "Add/Remove a Read Receipt"
.Picture = objPicture
.Mask = objMask
.Style = msoButtonIconAndCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub
Private Sub CreateButton1(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton1 = colCBcontrols.Add(msoControlButton, , "Standard",
, True)

With YourButton1
.Caption = "Save Copy"
.Move Befo=4
.TooltipText = "Save in Sent Items Folder"
.Style = msoButtonCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub

Friend Sub CloseInspector()
On Error Resume Next
Application.RemoveInspector m_lKey
Set YourButton = Nothing
Set YourButton1 = Nothing
Set m_oMailItem = Nothing
Set m_oInspector = Nothing
End Sub

Private Sub m_oInspector_Close()
CloseInspector
End Sub

Private Sub m_oMailItem_Close(Cancel As Boolean)
If m_oMailItem.Saved Then
CloseInspector
End If
End Sub

Private Sub m_oMailItem_Send(Cancel As Boolean)
CloseInspector
End Sub
Private Sub YourButton_Click1(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp1 As Outlook.Inspector
Dim objItem1 As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp1 = Application.ActiveInspector
If Not objInsp1 Is Nothing Then
Set objItem1 = objInsp1.CurrentItem
If objItem1.Class = olMail Then
' make sure it's unsent
If objItem1.Sent = False Then
' button action on
If YourButton1.State = msoButtonUp Then
YourButton1.State = msoButtonDown
Else
YourButton1.State = msoButtonUp
End If
If objItem1.DeleteAfterSubmit = False Then
objItem1.DeleteAfterSubmit = True
' button action off
Else
objItem1.DeleteAfterSubmit = False

  #4  
Old March 6th 06, 06:35 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 817
Default Adding a 2nd button (functionality not working)

I can't get your code to run at all. Upon review though, it appears you have
way more code than is necessary. The best I can recommend at this point it
to review how Inspectors can be trapped by my example he

Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legaul...cles/2224.aspx

I also recommend downloading the sample project here for guidelines and best
practices when working with custom toolbars/buttons:

Items Command Bar:
http://www.microeye.com/resources/itemsCB.htm

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Newt" wrote:

I can't get the 2nd button to do anything. I would like 2 buttons--one that
requests read receipts and one that saves a copy. When I put the code in for
both buttons, the "save copy" button doesn't work.

"Eric Legault [MVP - Outlook]" wrote:

What exactly do you mean? Do you want both functions - one to request a
receipt and the other to toggle saving a copy - to fire by one button? Or
are you just having troubleh having a second button do anything?

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Newt" wrote:

I'm a hack at writing this code, but here goes. I added a toggle button
several months ago that works great for adding Read Receipts. Now, I'd like
to add another button that allows me to select whether I save a copy in the
Sent Items folder. I figured out the correct code for one button, but don't
know how to make it work so that both buttons function together. Any help?

'THIS OUTLOOK SESSION
Private WithEvents m_oInspector As Outlook.Inspector
Private WithEvents m_oMailItem As Outlook.MailItem
Private WithEvents YourButton As Office.CommandBarButton
Private WithEvents YourButton1 As Office.CommandBarButton
Private m_lKey As Long

Friend Function Init(oInspector As Outlook.Inspector, ByVal lKey As Long) As
Boolean
Set m_oInspector = oInspector
Set m_oMailItem = oInspector.CurrentItem
If m_oMailItem.Sent = False Then
m_lKey = lKey
CreateButton oInspector
CreateButton1 oInspector
Init = True
End If
End Function

Private Sub CreateButton(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars
Dim objPicture As stdole.IPictureDisp
Dim objMask As stdole.IPictureDisp

Const PICTURE_PATH As String = "C:\Documents and
Settings\drhyase\Icons\readreceipt.bmp"
Const PICTURE_MASK As String = "C:\Documents and
Settings\drhyase\Icons\readreceiptmask.bmp"

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton = colCBcontrols.Add(msoControlButton, , "Standard", ,
True)
Set objPicture = LoadPicture(PICTURE_PATH)
Set objMask = LoadPicture(PICTURE_MASK)
With YourButton
.Caption = "&Read Receipt"
.Move Befo=3
.TooltipText = "Add/Remove a Read Receipt"
.Picture = objPicture
.Mask = objMask
.Style = msoButtonIconAndCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub
Private Sub CreateButton1(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton1 = colCBcontrols.Add(msoControlButton, , "Standard",
, True)

With YourButton1
.Caption = "Save Copy"
.Move Befo=4
.TooltipText = "Save in Sent Items Folder"
.Style = msoButtonCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub

Friend Sub CloseInspector()
On Error Resume Next
Application.RemoveInspector m_lKey
Set YourButton = Nothing
Set YourButton1 = Nothing
Set m_oMailItem = Nothing
Set m_oInspector = Nothing
End Sub

Private Sub m_oInspector_Close()
CloseInspector
End Sub

Private Sub m_oMailItem_Close(Cancel As Boolean)
If m_oMailItem.Saved Then
CloseInspector
End If
End Sub

Private Sub m_oMailItem_Send(Cancel As Boolean)
CloseInspector
End Sub
Private Sub YourButton_Click1(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp1 As Outlook.Inspector
Dim objItem1 As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp1 = Application.ActiveInspector
If Not objInsp1 Is Nothing Then
Set objItem1 = objInsp1.CurrentItem
If objItem1.Class = olMail Then
' make sure it's unsent
If objItem1.Sent = False Then
' button action on
If YourButton1.State = msoButtonUp Then
YourButton1.State = msoButtonDown
Else
YourButton1.State = msoButtonUp
End If
If objItem1.DeleteAfterSubmit = False Then
objItem1.DeleteAfterSubmit = True
' button action off
Else
objItem1.DeleteAfterSubmit = False
End If
End If
End If
End If

Set objInsp1 = Nothing
Set objItem1 = Nothing

End Sub

Private Sub YourButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp As Outlook.Inspector
Dim objItem As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp = Application.ActiveInspector
If Not objInsp Is Nothing Then
Set objItem = objInsp.CurrentItem
If objItem.Class = olMail Then
' make sure it's unsent
If objItem.Sent = False Then
' button action on
If YourButton.State = msoButtonUp Then
YourButton.State = msoButtonDown
Else
YourButton.State = msoButtonUp
End If
If objItem.ReadReceiptRequested = False Then
objItem.ReadReceiptRequested = True
' button action off
Else
objItem.ReadReceiptRequested = False
End If
End If
End If
End If

Set objInsp = Nothing
Set objItem = Nothing

End Sub

'CLASS MODULE (cInspector)
Private WithEvents m_oInspector As Outlook.Inspector
Private WithEvents m_oMailItem As Outlook.MailItem
Private WithEvents YourButton As Office.CommandBarButton
Private WithEvents YourButton1 As Office.CommandBarButton
Private m_lKey As Long

Friend Function Init(oInspector As Outlook.Inspector, ByVal lKey As Long) As
Boolean
Set m_oInspector = oInspector
Set m_oMailItem = oInspector.CurrentItem
If m_oMailItem.Sent = False Then
m_lKey = lKey
CreateButton oInspector
CreateButton1 oInspector
Init = True
End If
End Function

Private Sub CreateButton(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars
Dim objPicture As stdole.IPictureDisp
Dim objMask As stdole.IPictureDisp

Const PICTURE_PATH As String = "C:\Documents and
Settings\drhyase\Icons\readreceipt.bmp"
Const PICTURE_MASK As String = "C:\Documents and
Settings\drhyase\Icons\readreceiptmask.bmp"

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton = colCBcontrols.Add(msoControlButton, , "Standard", ,
True)
Set objPicture = LoadPicture(PICTURE_PATH)
Set objMask = LoadPicture(PICTURE_MASK)
With YourButton
.Caption = "&Read Receipt"
.Move Befo=3
.TooltipText = "Add/Remove a Read Receipt"
.Picture = objPicture
.Mask = objMask
.Style = msoButtonIconAndCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub
Private Sub CreateButton1(Inspector As Outlook.Inspector)
Dim objCB As Office.CommandBar
Dim colCB As Office.CommandBars

Set colCB = Inspector.CommandBars
Set objCB = colCB.Item("Standard")
Set colCBcontrols = objCB.Controls
Set YourButton1 = colCBcontrols.Add(msoControlButton, , "Standard",
, True)

With YourButton1
.Caption = "Save Copy"
.Move Befo=4
.TooltipText = "Save in Sent Items Folder"
.Style = msoButtonCaption

End With

Set objCB = Nothing
Set objCB = Nothing

End Sub

Friend Sub CloseInspector()
On Error Resume Next
Application.RemoveInspector m_lKey
Set YourButton = Nothing
Set YourButton1 = Nothing
Set m_oMailItem = Nothing
Set m_oInspector = Nothing
End Sub

Private Sub m_oInspector_Close()
CloseInspector
End Sub

Private Sub m_oMailItem_Close(Cancel As Boolean)
If m_oMailItem.Saved Then
CloseInspector
End If
End Sub

Private Sub m_oMailItem_Send(Cancel As Boolean)
CloseInspector
End Sub
Private Sub YourButton_Click1(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim objInsp1 As Outlook.Inspector
Dim objItem1 As MailItem

' get the currently open item and make sure it's a mail message
Set objInsp1 = Application.ActiveInspector
If Not objInsp1 Is Nothing Then
Set objItem1 = objInsp1.CurrentItem
If objItem1.Class = olMail Then
' make sure it's unsent
If objItem1.Sent = False Then
' button action on
If YourButton1.State = msoButtonUp Then
YourButton1.State = msoButtonDown
Else
YourButton1.State = msoButtonUp

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mistake made adding NEWS to GO button Computer Queen Outlook - Installation 1 March 8th 06 10:57 AM
Lost functionality mrniceguyinhannibal Outlook - Installation 0 February 8th 06 05:05 PM
adding a "print this slide" action button to powerpoint presentat ixratee Outlook - Using Forms 0 February 6th 06 11:14 PM
Command button not working on read page jbtempe Outlook - Using Forms 2 January 14th 06 12:25 AM
Outlook 2003 on Tablet PC and Inking functionality Sixpack Outlook - Installation 1 January 13th 06 05:39 PM


All times are GMT +1. The time now is 05:22 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2009 Outlook Banter, part of the NewsgroupBanter project.
The comments are property of their posters.
Channing Tatum - Debt Consolidation - Charity - Credit Cards - Debt Consolidation