Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing a subject line in VBA for Outlook 2003 1

Status
Not open for further replies.

irbk

MIS
Oct 20, 2004
578
US
Quick sum up of what I'm trying to do. User has a folder in there inbox that they want to archive the messages to the project server as .msg format (in order to preserve any attachments the message might have). Got the basic's of the program working fine. Program takes each message in the specified folder and saves it to the specified project server with the "Subject" of the e-mail as the file name. However, I've run across an issue with any e-mails that were replied to. As I'm sure you are aware, the subject of most replied to e-mails end up looking like "RE: Project Email" (assuming the original subject e-mail was "Project Email"). As I'm also sure you are aware a : in a file name just won't fly. So if the program encounters a : the e-mail is never saved.
So here is my question, If I test the item.subject (that's the variable I'm using) for a : can I some how programatically REMOVE the : while keeping the rest of the subject in tact? Using the above example take the subject of "RE: Project Email" and have VBA change it to "RE Project Email"???

Thanks in advance!
 
Have a look at the Replace function:
strFileName = Replace(objMailItem.Subject, ":", "")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV!!!
YOU ARE A GOD AMONG PROGRAMMERS!
In other words, that totally did the trick. Almost all of my VBA knowladge is self taught so there is always something new to learn. Tack "Replace function" into my brain...
Thanks again PHV!
 
Ok, now the next question along the same lines....
\,/,:,*,?,",<,>,|
all make for bad file names. I think that I can test for most of them, and using the Replace function so kindly provided by PHV, remove them from the subject line.
However
I'm pretty sure that I won't be able to test for
* or "
in the subject to replace them.
Any ideas?

Thanks again in advance.
 
Well, I'll be darned. It seems like even though ? and * are wild cards, I can still test for them and remove them with the Replace Function.
However, putting in a quote kills it.
Any suggestions on how to test for and remove
"
the subject line?
 
Use Chr(34) or """"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Tried it but I don't think I'm using the right syntax to use those. This is what I've tried

If item.Subject like """" then
item.Subject = Replace(item.Subject, """", "")
End If

and

If item.Subject like Chr(34) then
item.Subject = Replace(item.Subject, Chr(34), "")
End If

and

If item.Subject like "Chr(34)" then
item.Subject = Replace(item.Subject, "Chr(34), "")
End If

None of these 3 try's will enter the "If", they just skip right over it. What should the proper "IF" look like?

Thanks in advance again!
 
Why testing ?
item.Subject = Replace(item.Subject, """", "")
item.Subject = Replace(item.Subject, ">", "")
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ummm... Good question.
Don't quite know why I'm testing. I suppose it would just be easier to do the replace rather then test for the Character and then remove it if it exists.
Some times you miss the obvious stuff.......
Thanks again PH, not doing the test did the trick!

Now that I've got all the bad char's handled, on to figuring out what to do with files that are going to end up with the same file name. I'm sure that they are going to overwrite eachother, so I've got to come up with a way to prevent that from happening.

Again, Thanks Again!!
 
Looks like I've got everything squared away on this program now. Thanks for all your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top