PDA

View Full Version : Letter signature inserting before the body



e2027880
03-10-2014, 07:42 PM
I'm trying to programmatically create a letter and getting some problem.
On some workstations my vba-macro working wrong.

Details:
1. macro create replyAll to some letter
2. macro get the body of letter frome some template and insert it to the replyAll
3. then macro choose the signature
and on some workstations result letter have signature before body.

How can i fix this problem?
I want to have the same structure of letter on any workstation. Body and then signature, but not vice versa.
Using Outlook 2010 and code:


Sub Reply_finish()
path = "\\SHARED\mail_templates\Reply_finish.msg"
sName = "Notifications" 'Signature name

Dim oApp As New Outlook.Application
Dim oSel As Outlook.Selection

Set oSel = oApp.ActiveExplorer.Selection

Dim strMessageClass As String

Set oItem = oSel.Item(1)
strMessageClass = oItem.MessageClass

If (strMessageClass = "IPM.Note") Then
Set oMailItem = oItem
Set reply = oItem.ReplyAll
reply.BCC = oItem.BCC

Set tempItem = OpenTemplate(path)
reply.HTMLBody = AddTextToHtml(tempItem.Body, reply.HTMLBody)
reply.To = tempItem.To
Set tempItem = Nothing

reply.Display
Call SetSignature(reply, sName)
End If

Set oApp = Nothing
Set oExp = Nothing
Set oSel = Nothing
End Sub


Sub SetSignature(itm, signName)
If signName <> "" Then
itm.GetInspector.CommandBars.Item("Insert").Controls("&Подпись").Controls(signName).Execute
End If
End Sub

Function AddTextToHtml(text, html) As String
strStamp = "<p class=MsoNormal>" & text & "<o:p></o:p></p>"
intTagStart = InStr(1, html, "<body", _
vbTextCompare)
intTagEnd = InStr(intTagStart + 5, html, ">")
strBodyTag = _
Mid(html, _
intTagStart, intTagEnd - intTagStart + 1)
AddTextToHtml = Replace(html, strBodyTag, strBodyTag & strStamp)
End Function

Function OpenTemplate(path) As Outlook.MailItem
Dim Item As Outlook.MailItem
Set Item = Application.CreateItemFromTemplate(path)
Set OpenTemplate = Item
End Function