dakotafig
01-21-2012, 09:09 PM
I have some code that I have been working on to deal with the outlook problem of not defaulting to HTML format. The code works great for repy and reply all, but errors with a forward. By the way, I like this way much better than the mailitem.bodyformat = HTML because that method tends to screw with the font. So, here is my code, and does anyone have any ideas as to why the forward doesn't work? This is the line that the forward doesn't work:
ActiveInspector.CommandBars.FindControl(ID:=5564).Execute
Thanks.
OptionExplicit
Private WithEvents oExpl As Explorer
Private WithEvents oItem As MailItem
Private bDiscardEvents As Boolean
Private olFormat As OlBodyFormat
Private Sub Application_Startup()
'set default reply format to HTML
Set oExpl = Application.ActiveExplorer
bDiscardEvents = False
olFormat = olFormatHTML
End Sub
Private Sub oExpl_SelectionChange()
On ErrorResume Next
Set oItem = oExpl.Selection.Item(1)
End Sub
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
Call do_format(oItem.Reply, Cancel)
End Sub
Private Sub oItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
Call do_format(oItem.ReplyAll, Cancel)
End Sub
Private Sub oItem_Forward(ByVal Forward As Object, Cancel As Boolean)
Call do_format(oItem.Forward, Cancel)
End Sub
Private Sub do_format(mail_item As MailItem, Cancel As Boolean)
Dim format_needed As Boolean
'Set formating of email
If bDiscardEvents Or oItem.BodyFormat = olFormat Then
format_needed = False
Else
format_needed = True
End If
Cancel = True
bDiscardEvents = True
mail_item.Display
If format_needed Then
ActiveInspector.CommandBars.FindControl(ID:=5564).Execute
Call insert_sig
bDiscardEvents = False
End Sub
Sub insert_sig()
On Error Resume Next
Dim strFolder As String
Dim Signature As String
Dim sig1 As String
Dim sig2 As String
sig1 = "sig1"
sig2 = "sig2"
strFolder = ActiveExplorer.CurrentFolder.FolderPath
strFolder = Mid(strFolder, 3, InStr(3, strFolder, "\") - 3)
If strFolder = sig1 Then
Signature = "sig1"
ElseIf strFolder = ST Then
Signature = "sig1"
Else
'no signature
Exit Sub
End If
ActiveInspector.CommandBars("Menu Bar"). _
Controls("Insert"). _
Controls("Signature"). _
Controls(Signature).Execute
End Sub
ActiveInspector.CommandBars.FindControl(ID:=5564).Execute
Thanks.
OptionExplicit
Private WithEvents oExpl As Explorer
Private WithEvents oItem As MailItem
Private bDiscardEvents As Boolean
Private olFormat As OlBodyFormat
Private Sub Application_Startup()
'set default reply format to HTML
Set oExpl = Application.ActiveExplorer
bDiscardEvents = False
olFormat = olFormatHTML
End Sub
Private Sub oExpl_SelectionChange()
On ErrorResume Next
Set oItem = oExpl.Selection.Item(1)
End Sub
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
Call do_format(oItem.Reply, Cancel)
End Sub
Private Sub oItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
Call do_format(oItem.ReplyAll, Cancel)
End Sub
Private Sub oItem_Forward(ByVal Forward As Object, Cancel As Boolean)
Call do_format(oItem.Forward, Cancel)
End Sub
Private Sub do_format(mail_item As MailItem, Cancel As Boolean)
Dim format_needed As Boolean
'Set formating of email
If bDiscardEvents Or oItem.BodyFormat = olFormat Then
format_needed = False
Else
format_needed = True
End If
Cancel = True
bDiscardEvents = True
mail_item.Display
If format_needed Then
ActiveInspector.CommandBars.FindControl(ID:=5564).Execute
Call insert_sig
bDiscardEvents = False
End Sub
Sub insert_sig()
On Error Resume Next
Dim strFolder As String
Dim Signature As String
Dim sig1 As String
Dim sig2 As String
sig1 = "sig1"
sig2 = "sig2"
strFolder = ActiveExplorer.CurrentFolder.FolderPath
strFolder = Mid(strFolder, 3, InStr(3, strFolder, "\") - 3)
If strFolder = sig1 Then
Signature = "sig1"
ElseIf strFolder = ST Then
Signature = "sig1"
Else
'no signature
Exit Sub
End If
ActiveInspector.CommandBars("Menu Bar"). _
Controls("Insert"). _
Controls("Signature"). _
Controls(Signature).Execute
End Sub