PDA

View Full Version : Reply to All Messages



John_Mc
08-30-2007, 05:14 PM
Hi All,

As a newbie I've been playing with the code below that was written by Killian to reply to all messages that are selected at the time the macro button is hit, but am having some problems and can't figure out a solution.

When the txt file is read and put into the reply message, it deletes all the carriage returns, so everything is put next to each other, instead of having a blank line between paragraphs.

Also, I get a prompt asking for permission to send an email for each message - is there anyway of turning this off or only doing it once each time the macro is run?

Thanks for any help or advice you can offer,

Cheers,

John Mc






Sub main()

Dim myReply As MailItem
Dim objItem As MailItem

If Application.ActiveExplorer.Selection.Count > 0 Then
For Each objItem In Application.ActiveExplorer.Selection
If objItem.Class = olMail Then
Set myReply = objItem.Reply
myReply.Body = GetTextFromFile("C:\message.txt")
myReply.Display
End If
Next
End If

End Sub

Function GetTextFromFile(strPath As String) As String
Dim i As Long
Dim str As String

i = FreeFile
Open strPath For Input As #i
Do While Not EOF(1) ' Loop until end of file.
Input #i, str
GetTextFromFile = GetTextFromFile & str
Loop
Close

End Function

mvidas
08-31-2007, 05:17 AM
Hi John,

It looks like the GetTextFromFile function isn't re-inserting the end-of-line characters into the string (after each retrieved record), so that is why the string is not as it should be. Try the following instead:Function GetTextFromFile(strPath As String) As String
Dim i As Long
Dim tempStr As String 'changed from str to avoid the Str function confusion

i = FreeFile
Open strPath For Binary As #i
tempStr = Space$(LOF(i))
Get #i, , tempStr
Close #i

GetTextFromFile = tempStr
End Function

As for the security message, check out a program called ClickYes that basically clicks that "Yes" message for you. Or better yet, get the COM Add-in made by mapilab called Advanced Security (free) which you can specify which programs you want to have unfettered access (http://www.mapilab.com/outlook/security/).

Matt

John_Mc
09-02-2007, 06:16 PM
Hi Matt,

Thanks for this, it works a treat and has sorted out the formatting.

I've been tinkering for a while now - how do i add in a loop so that it will do it for all selected messages? At the moment, a message pops up all ready to send, but isn't actually sent automatically?

I've been trying to use end of file, but keep gettting it wrong.:bug:

Sorry to come back to you, but i'm sure it's one or two lines of code for you :bow:

Cheers,

John Mc

mvidas
09-04-2007, 04:45 AM
Hi John,

Sorry about the delay. From what I see, the code already loops through the selected messages. To get them to send instead of just popping up ready to send, change myReply.Display to myReply.Send and you should be all set!

Matt

John_Mc
09-11-2007, 06:45 PM
Hi Matt,

Magic - works perfectly, which has saved us loads of work (plus we'll use it in future).

thanks for taking the time to help me out,

Cheers,

John Mc

geekgirlau
09-11-2007, 07:55 PM
Don't forget to mark this thread as "Solved" (use the Thread Tools at the top of the page)