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

Replying to an e-mail with boilerplate text and an attachment



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old March 31st 08, 03:57 PM posted to microsoft.public.outlook.program_vba
peeweejd
external usenet poster
 
Posts: 2
Default Replying to an e-mail with boilerplate text and an attachment

Hi,

I'm decent at programming VBA in Excel and Access, but I have no
experience at all with Outlook. I'm using Outlook 2000 right now.

I want to easily be able to reply to the message that is open with
some text ("thank you mr. customer sir we love you, bah, blah, blah" )
and an attachment (a pdf copy of my companies terms and conditions).

I tried it already by creating a template that I copy/paste but it
gets hung up when the message format is HTML or text.

Can someone walk me through this or point to an example? Is VB the
right way to do this?

Thanks in advance!
  #2  
Old March 31st 08, 07:42 PM posted to microsoft.public.outlook.program_vba
JP[_3_]
external usenet poster
 
Posts: 201
Default Replying to an e-mail with boilerplate text and an attachment

One way:

First set up a signature with the boilerplate text. Then paste this
code in a standard module in the Outlook VBE.

(Note: I did not write this code, it was adapted from outlookcode.com
and rondebruin.nl)

Sub SendBoilerReply()
Call SendStockMsg("Signature name", "Filename/path")
End Sub

Replace "Signature name" with the name of the signature you created,
and replace "Filename/path" with the fully qualified path and filename
of the file you want to attach. For example, if your signature was
named "Boilerplate Client Response" and you were attaching "C:
\ThankYou.PDF", the code would look like this.

Option Explicit
Sub SendBoilerReply()
Call SendStockMsg("Boilerplate Client Response", "C:
\ThankYou.PDF")
End Sub

Create as many signatures as you need, just copy and paste the above
code and change the references accordingly. If you attach the macro to
a toolbar button, it will be even more user friendly (see "How to
assign a macro to a toolbar button" at http://codeforexcelandoutlook.com/ResendMsg.html
if you need placement assistance).

Then paste in this code in the same module:

Sub SendStockMsg(SigName As String, Optional sFile As String)

Dim myItem As Outlook.MailItem
Dim olNewMailItem As Outlook.MailItem
Dim SigString As String
Dim Signature As String

' get valid ref to current item
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set myItem = ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set myItem = ActiveInspector.CurrentItem
Case Else
End Select
On Error GoTo 0

If myItem Is Nothing Then
MsgBox "Could not use current item. Please select or open a
single email.", vbInformation
GoTo ExitProc
End If

SigString = "C:\Documents and Settings\" & Environ("username") & _
"\Application Data\Microsoft\Signatures\" & SigName &
".htm"

If Dir(SigString) "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If

Set olNewMailItem = myItem.Reply

olNewMailItem.HTMLBody = Signature & olNewMailItem.HTMLBody

If sFile "" Then
olNewMailItem.Attachments.Add(sFile)
End If

olNewMailItem.Display

myItem.UnRead = False

ExitProc:

Set olNewMailItem = Nothing

End Sub

Function GetBoiler(ByVal sFile As String) As String
' from Dick Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.ReadAll
ts.Close
End Function


The filename argument is optional, so if you had a stock reply you
wanted to send, but didn't want to include an attachment, this code
would work:

Sub SendBoilerReply()
Call SendStockMsg("Signature name")
End Sub

This code will work if you select one item when viewing your mailbox,
or on the currently open mail item. Note that it looks for the
signature file in this folder:

C:\Documents and Settings\"username"\Application Data\Microsoft
\Signatures\

If your folder is different, change the path accordingly. (search for
"signature name".htm to find the correct folder)


ps- your stock reply sounds a bit like the "bug letter" urban legend

:-)

http://www.snopes.com/business/consumer/bedbug.asp


HTH,
JP

On Mar 31, 9:57*am, peeweejd wrote:
Hi,

I'm decent at programming VBA in Excel and Access, but I have no
experience at all with Outlook. *I'm using Outlook 2000 right now.

I want to easily be able to reply to the message that is open with
some text ("thank you mr. customer sir we love you, bah, blah, blah" )
and an attachment (a pdf copy of my companies terms and conditions).

I tried it already by creating a template that I copy/paste but it
gets hung up when the message format is HTML or text.

Can someone walk me through this or point to an example? *Is VB the
right way to do this?

Thanks in advance!


  #3  
Old March 31st 08, 08:25 PM posted to microsoft.public.outlook.program_vba
peeweejd
external usenet poster
 
Posts: 2
Default Replying to an e-mail with boilerplate text and an attachment

On Mar 31, 1:42 pm, JP wrote:
One way:

First set up asignaturewith the boilerplate text. Then paste this
code in a standard module in the Outlook VBE.


Thanks for the help. I tried it, but all of the previous text is
wiped out by the signature.

ps- your stockreplysounds a bit like the "bug letter" urban legend


yeah, I didn't think that I should bore you all with my schmoozing ;-)

Thanks for the help. I may just use the "signature" trick. It's
really too bad that you cannot add an attachment to a signature file.
  #4  
Old March 31st 08, 08:56 PM posted to microsoft.public.outlook.program_vba
JP[_3_]
external usenet poster
 
Posts: 201
Default Replying to an e-mail with boilerplate text and an attachment

What do you mean "previous text"? You mean the text of the original
message? In my testing the code replies to the message then inserts
the boilerplate text at the top, exactly as if you had done so
manually. The original text of the message is preserved at the bottom
of the stock reply.

That is what this line does:

olNewMailItem.HTMLBody = Signature & olNewMailItem.HTMLBody

It sets the HTMLBody property of the new message to the text of the
signature (the boilerplate text) then appends the original text of the
reply (as if you had pressed "Reply").

You don't need to add the attachment to the signature. As I mentioned
in the previous message, you can specify an attachment in the call to
the function. This makes it more flexible in that you can have
different boilerplates and attachments for different situations.


HTH,
JP

On Mar 31, 2:25*pm, peeweejd wrote:
On Mar 31, 1:42 pm, JP wrote:

One way:


First set up asignaturewith the boilerplate text. Then paste this
code in a standard module in the Outlook VBE.


Thanks for the help. *I tried it, but all of the previous text is
wiped out by the signature.

ps- your stockreplysounds a bit like the "bug letter" urban legend


yeah, I didn't think that I should bore you all with my schmoozing ;-)

Thanks for the help. *I may just use the "signature" trick. *It's
really too bad that you cannot add an attachment to a signature file.


  #5  
Old March 31st 08, 10:36 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Replying to an e-mail with boilerplate text and an attachment

That statement won't work as you expect it to, because it puts the signature *outside* the htmlbody and /body/html tags when instead it needs to go inside -- *and* be completely tagged HTML content. In other words, it takes a bit of text parsing with the Instr(), Mid(), and Left() functions.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"JP" wrote in message ...
What do you mean "previous text"? You mean the text of the original
message? In my testing the code replies to the message then inserts
the boilerplate text at the top, exactly as if you had done so
manually. The original text of the message is preserved at the bottom
of the stock reply.

That is what this line does:

olNewMailItem.HTMLBody = Signature & olNewMailItem.HTMLBody

It sets the HTMLBody property of the new message to the text of the
signature (the boilerplate text) then appends the original text of the
reply (as if you had pressed "Reply").

You don't need to add the attachment to the signature. As I mentioned
in the previous message, you can specify an attachment in the call to
the function. This makes it more flexible in that you can have
different boilerplates and attachments for different situations.


HTH,
JP

On Mar 31, 2:25 pm, peeweejd wrote:
On Mar 31, 1:42 pm, JP wrote:

One way:


First set up asignaturewith the boilerplate text. Then paste this
code in a standard module in the Outlook VBE.


Thanks for the help. I tried it, but all of the previous text is
wiped out by the signature.

ps- your stockreplysounds a bit like the "bug letter" urban legend


yeah, I didn't think that I should bore you all with my schmoozing ;-)

Thanks for the help. I may just use the "signature" trick. It's
really too bad that you cannot add an attachment to a signature file.


  #6  
Old March 31st 08, 10:52 PM posted to microsoft.public.outlook.program_vba
JP[_3_]
external usenet poster
 
Posts: 201
Default Replying to an e-mail with boilerplate text and an attachment

Good point Sue, but it still does what the OP wants :-)

--JP


On Mar 31, 4:36*pm, "Sue Mosher [MVP-Outlook]"
wrote:
That statement won't work as you expect it to, because it puts the signature *outside* the htmlbody and /body/html tags when instead it needs to go inside -- *and* be completely tagged HTML content. In other words, it takes a bit of text parsing with the Instr(), Mid(), and Left() functions.

--
Sue Mosher, Outlook MVP
* *Author of Microsoft Outlook 2007 Programming:
* * *Jumpstart for Power Users and Administrators
* *http://www.outlookcode.com/article.aspx?id=54

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
replying to plain text Brad White Outlook - General Queries 3 August 3rd 07 10:52 AM
I Don't Want to Check Spelling of Original Text When Replying razor Outlook - Installation 0 June 5th 07 08:54 PM
mail format to plain text autom., when replying to rtf or html mai Martinez Outlook - Installation 2 April 13th 06 09:01 PM
Retain attachment when replying [email protected] Outlook and VBA 6 April 1st 06 12:14 AM
Missing Body Text But Appears When Replying or Forwarding Asin Outlook - Installation 0 February 7th 06 02:42 AM


All times are GMT +1. The time now is 09:22 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.