PC Review


Reply
Thread Tools Rate Thread

Code not moving through messages

 
 
PJFry
Guest
Posts: n/a
 
      12th Nov 2009
The code below archives my messages into a local folder. What I want to do
is to have each message stamped with an 'Archived' noted so I know it has
already been done and have the code skip that message.

The problem I am having is that the 'Archived to" string is only inserted
into the message body that I have selected when I exectute the code. If I
have no messages select, none of them are altered.

The messages save ok, but what am I missing that keeps the itm.Body from
being updated?

Sub SaveMessages()

Dim OL As Application
Dim NmeSpace As NameSpace
Dim SubTxt As String

Set OL = CreateObject("Outlook.Application")
Set NmeSpace = OL.GetNamespace("MAPI")
Set Inbx = NmeSpace.GetDefaultFolder(olFolderInbox)
Set fldr = Application.ActiveExplorer.CurrentFolder
DirName = "C:\Documents and Settings\PJFry\Email\"

For Each itm In fldr.Items

SubTxt = itm.Subject
SubTxt = Replace(SubTxt, "_", "")
SubTxt = Replace(SubTxt, "´", "'")
SubTxt = Replace(SubTxt, "`", "'")
SubTxt = Replace(SubTxt, "{", "(")
SubTxt = Replace(SubTxt, "[", "(")
SubTxt = Replace(SubTxt, "]", ")")
SubTxt = Replace(SubTxt, "}", ")")
SubTxt = Replace(SubTxt, "/", "-")
SubTxt = Replace(SubTxt, "\", "-")
SubTxt = Replace(SubTxt, ":", "")
SubTxt = Replace(SubTxt, ",", "")
'Cut out invalid signs.
SubTxt = Replace(SubTxt, "*", "'")
SubTxt = Replace(SubTxt, "?", "")
SubTxt = Replace(SubTxt, """", "'")
SubTxt = Replace(SubTxt, "<", "")
SubTxt = Replace(SubTxt, ">", "")
SubTxt = Replace(SubTxt, "|", "")


FNme = DirName & Trim(SubTxt) & " " & Format(itm.ReceivedTime,
"yy.mm.dd") & " " & itm.SenderName & ".msg"

If itm.Class = olMail Then
If InStr(1, itm.Body, "Archived to") > 0 Then
'do nothing
Else
itm.Body = itm.Body & vbCrLf & _
"Archived to " & DirName & " on " & Now()
itm.SaveAs FNme, olMSG
End If
End If


Next itm


End Sub


If there is a better way to accomplish the same thing, I would also love to
hear it.

Thanks!

PJ
 
Reply With Quote
 
 
 
 
Dmitry Streblechenko
Guest
Posts: n/a
 
      12th Nov 2009
You never call itm.Save
Are you sure you want to modify &all* the messages in the Inbox folder
convertign them to plain text in the mean time?
Why not use Application.ActiveExplorer.Selection collection to give the user
more control over which messages get modified?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"PJFry" <(E-Mail Removed)> wrote in message
news:10CC524F-8F98-44E4-8C10-(E-Mail Removed)...
> The code below archives my messages into a local folder. What I want to
> do
> is to have each message stamped with an 'Archived' noted so I know it has
> already been done and have the code skip that message.
>
> The problem I am having is that the 'Archived to" string is only inserted
> into the message body that I have selected when I exectute the code. If I
> have no messages select, none of them are altered.
>
> The messages save ok, but what am I missing that keeps the itm.Body from
> being updated?
>
> Sub SaveMessages()
>
> Dim OL As Application
> Dim NmeSpace As NameSpace
> Dim SubTxt As String
>
> Set OL = CreateObject("Outlook.Application")
> Set NmeSpace = OL.GetNamespace("MAPI")
> Set Inbx = NmeSpace.GetDefaultFolder(olFolderInbox)
> Set fldr = Application.ActiveExplorer.CurrentFolder
> DirName = "C:\Documents and Settings\PJFry\Email\"
>
> For Each itm In fldr.Items
>
> SubTxt = itm.Subject
> SubTxt = Replace(SubTxt, "_", "")
> SubTxt = Replace(SubTxt, "´", "'")
> SubTxt = Replace(SubTxt, "`", "'")
> SubTxt = Replace(SubTxt, "{", "(")
> SubTxt = Replace(SubTxt, "[", "(")
> SubTxt = Replace(SubTxt, "]", ")")
> SubTxt = Replace(SubTxt, "}", ")")
> SubTxt = Replace(SubTxt, "/", "-")
> SubTxt = Replace(SubTxt, "\", "-")
> SubTxt = Replace(SubTxt, ":", "")
> SubTxt = Replace(SubTxt, ",", "")
> 'Cut out invalid signs.
> SubTxt = Replace(SubTxt, "*", "'")
> SubTxt = Replace(SubTxt, "?", "")
> SubTxt = Replace(SubTxt, """", "'")
> SubTxt = Replace(SubTxt, "<", "")
> SubTxt = Replace(SubTxt, ">", "")
> SubTxt = Replace(SubTxt, "|", "")
>
>
> FNme = DirName & Trim(SubTxt) & " " & Format(itm.ReceivedTime,
> "yy.mm.dd") & " " & itm.SenderName & ".msg"
>
> If itm.Class = olMail Then
> If InStr(1, itm.Body, "Archived to") > 0 Then
> 'do nothing
> Else
> itm.Body = itm.Body & vbCrLf & _
> "Archived to " & DirName & " on " & Now()
> itm.SaveAs FNme, olMSG
> End If
> End If
>
>
> Next itm
>
>
> End Sub
>
>
> If there is a better way to accomplish the same thing, I would also love
> to
> hear it.
>
> Thanks!
>
> PJ



 
Reply With Quote
 
Sue Mosher [MVP]
Guest
Posts: n/a
 
      13th Nov 2009
You're not saving the item after you change the Body. You're only saving the
archived copy.

FWIW, I see nothing in the code you posted that deals with selected items.

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


"PJFry" <(E-Mail Removed)> wrote in message
news:10CC524F-8F98-44E4-8C10-(E-Mail Removed)...
> The code below archives my messages into a local folder. What I want to
> do
> is to have each message stamped with an 'Archived' noted so I know it has
> already been done and have the code skip that message.
>
> The problem I am having is that the 'Archived to" string is only inserted
> into the message body that I have selected when I exectute the code. If I
> have no messages select, none of them are altered.
>
> The messages save ok, but what am I missing that keeps the itm.Body from
> being updated?
>
> Sub SaveMessages()
>
> Dim OL As Application
> Dim NmeSpace As NameSpace
> Dim SubTxt As String
>
> Set OL = CreateObject("Outlook.Application")
> Set NmeSpace = OL.GetNamespace("MAPI")
> Set Inbx = NmeSpace.GetDefaultFolder(olFolderInbox)
> Set fldr = Application.ActiveExplorer.CurrentFolder
> DirName = "C:\Documents and Settings\PJFry\Email\"
>
> For Each itm In fldr.Items
>
> SubTxt = itm.Subject
> SubTxt = Replace(SubTxt, "_", "")
> SubTxt = Replace(SubTxt, "´", "'")
> SubTxt = Replace(SubTxt, "`", "'")
> SubTxt = Replace(SubTxt, "{", "(")
> SubTxt = Replace(SubTxt, "[", "(")
> SubTxt = Replace(SubTxt, "]", ")")
> SubTxt = Replace(SubTxt, "}", ")")
> SubTxt = Replace(SubTxt, "/", "-")
> SubTxt = Replace(SubTxt, "\", "-")
> SubTxt = Replace(SubTxt, ":", "")
> SubTxt = Replace(SubTxt, ",", "")
> 'Cut out invalid signs.
> SubTxt = Replace(SubTxt, "*", "'")
> SubTxt = Replace(SubTxt, "?", "")
> SubTxt = Replace(SubTxt, """", "'")
> SubTxt = Replace(SubTxt, "<", "")
> SubTxt = Replace(SubTxt, ">", "")
> SubTxt = Replace(SubTxt, "|", "")
>
>
> FNme = DirName & Trim(SubTxt) & " " & Format(itm.ReceivedTime,
> "yy.mm.dd") & " " & itm.SenderName & ".msg"
>
> If itm.Class = olMail Then
> If InStr(1, itm.Body, "Archived to") > 0 Then
> 'do nothing
> Else
> itm.Body = itm.Body & vbCrLf & _
> "Archived to " & DirName & " on " & Now()
> itm.SaveAs FNme, olMSG
> End If
> End If
>
>
> Next itm
>
>
> End Sub
>
>
> If there is a better way to accomplish the same thing, I would also love
> to
> hear it.
>
> Thanks!
>
> PJ



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Moving Estimate, Local Movers, Long Distance Moving, PackingSupplies, Storage Rental, Home Moving, Apartment Moving, Office Moving,Commercial Moving linkswanted Microsoft ASP .NET 0 6th Jan 2008 04:45 AM
What is the best way to moving managed code to unmanaged code? sachin Microsoft Dot NET Framework Forms 11 16th Aug 2004 07:15 PM
What is the best way to moving managed code to unmanaged code? sachin Microsoft Dot NET 5 12th Aug 2004 12:06 PM
Moving messages from Drafts to Outbox doesn't send messages Tad Microsoft Outlook 0 21st May 2004 06:21 PM
Moving Messages Ron Microsoft Outlook Discussion 0 7th Apr 2004 07:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:15 AM.