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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook 2007 search & replace hyphens in Subject 1

Status
Not open for further replies.

dcompto

Technical User
Jul 5, 2001
751
US
Using VBA in Outlook 2007, can someone tell me how I can code to change an en dash to a hyphen IN THE SUBJECT LINE?

I have already managed to put together code that cycles through each mailitem in a picked folder and saves each attachment using its mailitem's custom Subject line, but I need to modify the code to include changing the en dashes to hyphens.

Thanks for any help!!!

EXPLANATION:
I distributed an Acrobat form to 204 employees and used Javascript to customize the Submit button so that the subject line of each employee's RETURN email would be sorted by Lastname, Firstname in Outlook.

Some of the forms have been returned with en dashes instead of hyphens in the Subject line and, although they still sort correctly in Outlook, they don't in the hard drive's folder in which the attachments are being saved.
 
Which code ?
Tip: you may consider the Replace function

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry, I am not a programmer and I obviously do not know the correct terminology to phrase my question. Even though I've looked at examples of the Replace function before I posted my initial question, I do not understand HOW to incorporate it into my macro.

My code is:
Code:
Public Sub ExportAtmt()
On Error Resume Next
Dim otlNameSpace As Outlook.NameSpace
Dim otlFolder As Outlook.MAPIFolder
Dim Atmt As Outlook.Attachment
Dim Item As Outlook.MailItem
[COLOR=green]'Dim StrSubject As String[/color green]
Set otlNameSpace = Outlook.GetNamespace("MAPI")
Set otlFolder = otlNameSpace.PickFolder
[COLOR=green]'for each item in current folder[/color green]
For Each Item In otlFolder.Items
[COLOR=green]'for each attachment[/color green]
   For Each Atmt In Item.Attachments
        Atmt.SaveAsFile "G:\Quiz Temp Folder\" & Item.Subject & ".pdf"
[COLOR=green]'            & " - " & Format(Item.CreationTime, "yyyymmdd_hhnnss_")[/color green]
   Next Atmt
Next Item
 
Set Atmt = Nothing
Set Item = Nothing
Set otlFolder = Nothing
Set otlNameSpace = Nothing
 
End Sub
Each message in the picked folder has a subject line which is formatted as:

[tt]HazCom Quiz - Lastname, Firstname[/tt]

However, on some of the messages, the hyphen in the Subject line somehow got changed to an en dash.

For each message that has an en dash, I want to change the en dash to a hyphen before (or at the time) it is used in the[/color red] [tt]Atmt.SaveAsFile...[/tt] line of code. How can I modify my code to accomplish this?[/color red]
 
Code:
Atmt.SaveAsFile "G:\Quiz Temp Folder\" & Replace(Item.Subject, Chr(150), "-") & ".pdf"
En-Dash has Ascii character code 150
 
Golom,

Bless you, bless you, bless you!

It seems so very simple now that I see the actual code. I was just making it harder (in my way of thinking) than it needed to be.

I can't thank you enough!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top