PDA

View Full Version : Outlook to reply to email when moved to folder



SIXfoot5ins
10-20-2012, 03:53 PM
Hi guys,
I found a VB script here forums.techguy.org/business-applications/439567-outlook-reply-email-when-mail.html which I've got working but would like to send an email which is longer with a few paragraphs of text, perhaps from a text file?

I've tried multiple .Body lines but it only recognises the first one.

I'm a bit stumped and dont know how to get the script to use a text file instead of the .Body line.

Any help would be great!

Thanks guys

Crocus Crow
10-22-2012, 10:03 AM
You can't have multiple .Body statements because the Mail object has only one Body property; you have to put each line in the single Body property.

To read lines from a text file use either VBA file I/O statements (Open, Input #, etc.) or FileSystemObject methods like OpenTextFile, ReadLine or ReadAll.

Post your code if you need further help with this.

SIXfoot5ins
10-22-2012, 10:25 AM
Hi Crocus Crow,
Thank you for replying with your advice :)
I tried using one .Body statement but couldn't figure out how to get a new line to add another paragraph.

Here's the code I found...

Option Explicit
'##############################################
'### all code for the ThisOutlookSession module
'### Module level Declarations
'expose the items in the target folder to events
Dim WithEvents TargetFolderItems As Items

'###############################################
Private Sub Application_Startup()
'some startup code to set our "event-sensitive"
'items collection
Dim ns As Outlook.NameSpace
'
Set ns = Application.GetNamespace("MAPI")
Set TargetFolderItems = ns.Folders.Item( _
"Personal Folders").Folders.Item("Temp").Items

End Sub

'#################################################
'### this is the ItemAdd event code
Sub TargetFolderItems_ItemAdd(ByVal Item As Object)
'when a new item is added to our "watched folder"
'we can process it

Dim myReply As MailItem

Set myReply = Item.Reply
With myReply
.Subject = "Auto-reply to " & Item.Subject
.Body = "Some body text here"
.Send
End With

End Sub

'#################################################
Private Sub Application_Quit()

Dim ns As Outlook.NameSpace
Set TargetFolderItems = Nothing
Set ns = Nothing

End Sub

...how can I add a new line in .Body = "Some body text here" ?
I dont know VBA but looked into vbCrLf but couldnt get that working either.

Thank you.

Crocus Crow
10-22-2012, 01:25 PM
Simply:

.Body = "Some body text here" & vbCrLf & "Another line." & vbCrLf & vbCrLf & "New paragraph with blank line above...."

For the text file, please search the terms I mentioned and you should find many examples.

SIXfoot5ins
11-07-2012, 05:07 PM
Simply:

.Body = "Some body text here" & vbCrLf & "Another line." & vbCrLf & vbCrLf & "New paragraph with blank line above...."

For the text file, please search the terms I mentioned and you should find many examples.

Thanks Crocus Crow, sorry I just seen your reply as I've been away
Thanks again
:)

williamjhone
11-16-2012, 10:30 PM
function being called is GetAllFilesInDir , after that i show how i am using it. All the variables are correct, tried all the trouble shooting i can think of... hope you guys have an idea!!