PDA

View Full Version : Modify CSV File with wordpad



bradh_nz
02-15-2010, 04:46 PM
I have the following vba in outlook that strips out attachments and saves them in a folder. This works perfectly.

However the next step is to open these csv file in wordpad and preform a find & replace. I cant open these up in excel and preform this as it messes up the format. I use the sendkeys option but for some reason on the second file it places a blank line at the start. Is there a more robust way to do this?

Thanks


Sub SaveToFolderCSV(MyMail As MailItem)
Dim strID As String
Dim objNS As Outlook.NameSpace
Dim objMail As Outlook.MailItem
Dim objAtt As Outlook.Attachment
Dim c As Integer

'Place path to sav to on next line.
Const save_path As String = "G:\Jitterbit\GO\Production\DDR\Source\DDR"

'Error_Trapping
On Error GoTo GetError_err

strID = MyMail.EntryID
Set objNS = Application.GetNamespace("MAPI")
Set objMail = objNS.GetItemFromID(strID)

If objMail.Attachments.Count > 0 Then
For c = 1 To objMail.Attachments.Count
Set objAtt = objMail.Attachments(c)
save_name = objAtt.FileName
objAtt.SaveAsFile save_path & save_name
Call Transfer_CSV_Data(save_name)
Next
End If

GetError_err:
Error_Message = "Error Saving CSV Files"
Set objAtt = Nothing
Set objMail = Nothing
Set objNS = Nothing

'fixes delete first line that is placed in csv for no reason what so ever
'Call Blank_Fix

End Sub
Sub Transfer_CSV_Data(save_name As String)
Shell "notepad.exe G:\Jitterbit\GO\Production\DDR\Source\DDR" & save_name, vbMaximizedFocus ' open a txt document
SendKeys "^h" 'CTRL + H (Replace)
SendKeys "DP" 'SHIFT + 2 (")
SendKeys "{TAB}"
SendKeys "MG"
SendKeys "%a" 'ALT + A (Replace All)
SendKeys "{esc}"
SendKeys "^s" 'CTRL + s (Save)
SendKeys "%{F4}~" 'ALT + F4 (Close)
End Sub