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

Replace Text for all files in a folder 1

Status
Not open for further replies.

VBegin

Technical User
Apr 25, 2011
6
0
0
US
Hey, Was wondering if someone could lend a hand. I have some VBA code for outlook that allows me to take all the attechments in a selected folder and save them as a .TXT file from xml. I am ultimately looking to add all the data into an excel database but first must switch all the text for the files (around 1000 of them). I only need to change the characters "<" and ">" to "^" so that I can import them as a "^" delimited file to excel. Would like to do this in the same application as my outlook attachment save which is done as follows:

Sub saveAttachments()
Dim myOlApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myAttachment As Outlook.Attachment
Dim myItems As Outlook.Items
Dim strFolder As String
Dim myFolder As Object
Dim myExplorer As Outlook.Explorer
Dim obj As Outlook.MailItem
Dim LResult As String



On Error Resume Next

strFolder = "H:\DUMP\"

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
'Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myFolder = myNameSpace.PickFolder
Set myExplorer = myFolder.GetExplorer
Set myItems = myFolder.Items
'myExplorer.Display

For Each obj In myItems
For Each myAttachment In obj.Attachments
myAttachment.SaveAsFile strFolder _
& myAttachment.DisplayName & ".TXT"
Next
Next

Set myOlApp = Nothing
Set myNameSpace = Nothing
Set myFolder = Nothing
Set myExplorer = Nothing
Set myItems = Nothing

End Sub


Please help me! I am not even sure where to begin

J
 
You can look at the FileSystemObject.OpenTextFile(fname,mode,create,format)
or some of the other FileSystemObjects.

If you open it for appending, you may be able to use the
Replace() function to find ">" and "<" and replace them with the "^".

FileSystemObjects is usually listed under ASP, but it works fine in a VBA module.

Paul
 
This guy has got like three threads all fishing for someone to write his code.......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top