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

VBA Challenge

Status
Not open for further replies.

VBegin

Technical User
Apr 25, 2011
6
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
 
'declare and initiate required objects
Dim fs As FileSystemObject
Dim ts As TextStream

Set fs = New FileSystemObject

'To write
Set ts = fs.OpenTextFile("C:\mytestfile.txt", ForWriting, True)
ts.WriteLine "I Love"
ts.WriteLine "VB Forums"
ts.Close

'To Read
If fs.FileExists("C:\mytestfile.txt") Then
Set ts = fs.OpenTextFile("C:\mytestfile.txt")

Do While Not ts.AtEndOfStream
MsgBox ts.ReadLine
Loop
ts.Close
End If

'clear memory used by FSO objects
Set ts = Nothing
Set fs = Nothing
 
not quite what i was looking for, looking to replace the characters (< and >) in the text file with "^"....any idea? i know this will somehow involve automated opening of each file and using the replace command but thats all that I have
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top