I'm convinced this can be done but it seems it is way beyond my skill level (I'm a total novice)
Several times a day a customer sends me a .csv file that I use to generate an order, I need to keep a running log of all of the data in these .csv files in a summary workbook.
I have a code in my summary workbook that takes every attachment I need from an Outlook folder and places them in a folder on my computer. Seems like a good starting point.
I then need to copy the data from each .cvs and paste it into the summary workbook, I don't know if its easier to automatically process each file as it comes in or process a batch at a time, maybe on a schedule at the end of each day, I don't even really mind having to manually trigger the action to process all outstanding files. I should note that these emails can arrive whilst my PC is not on. I know you can trigger Macros from Outlook rules, that could be a good option
I have also have tested a code that opens a single .csv and copies the data where I need it, this seems to work.
I need help dealing with multiple .csv files, or a method for dealing with one at a time, and I also need to figure out how to add a date in Column B and a week number for that week in Column A for each row of data imported, the date is in the file name or I was think using Date Created might work.
Please ask if you need any more information.
Any help would be massively appreciated.
Several times a day a customer sends me a .csv file that I use to generate an order, I need to keep a running log of all of the data in these .csv files in a summary workbook.
I have a code in my summary workbook that takes every attachment I need from an Outlook folder and places them in a folder on my computer. Seems like a good starting point.
Code:
Sub Test()
SaveAttachments "Test", "csv", "C:\Users\Desktop\Test"
End Sub
Sub SaveAttachments(OutlookFolderInInbox As String, _
ExtString As String, DestFolder As String)
Dim ns As Namespace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim I As Integer
On Error GoTo ThisMacro_err
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders(OutlookFolderInInbox)
I = 0
If SubFolder.Items.Count = 0 Then
MsgBox "There are no messages in this folder : " & OutlookFolderInInbox, _
vbInformation, "Nothing Found"
Set SubFolder = Nothing
Set Inbox = Nothing
Set ns = Nothing
Exit Sub
End If
If Right(DestFolder, 1) <> "\" Then
DestFolder = DestFolder & "\"
End If
For Each Item In SubFolder.Items
For Each Atmt In Item.Attachments
If LCase(Right(Atmt.FileName, Len(ExtString))) = LCase(ExtString) Then
FileName = DestFolder & " " & Atmt.FileName
Atmt.SaveAsFile FileName
I = I + 1
End If
Next Atmt
Next Item
ThisMacro_exit:
Set SubFolder = Nothing
Set Inbox = Nothing
Set ns = Nothing
Exit Sub
ThisMacro_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: SaveEmailAttachmentsToFolder" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume ThisMacro_exit
End Sub
I then need to copy the data from each .cvs and paste it into the summary workbook, I don't know if its easier to automatically process each file as it comes in or process a batch at a time, maybe on a schedule at the end of each day, I don't even really mind having to manually trigger the action to process all outstanding files. I should note that these emails can arrive whilst my PC is not on. I know you can trigger Macros from Outlook rules, that could be a good option
I have also have tested a code that opens a single .csv and copies the data where I need it, this seems to work.
Code:
Sub Copy()
Dim Import As Workbook
Dim Export As Workbook
Set Import = Workbooks("Test import.xlsm")
Set Export = Workbooks.Open("C:\User\Desktop\Test\Test Export.csv")
With Export.Sheets("Test Export").UsedRange
Import.Sheets("Summary").Range("C" & Rows.Count).End(xlUp).Offset(1).Resize( _
.Rows.Count, .Columns.Count) = .Value
End With
Export.Close
End Sub
I need help dealing with multiple .csv files, or a method for dealing with one at a time, and I also need to figure out how to add a date in Column B and a week number for that week in Column A for each row of data imported, the date is in the file name or I was think using Date Created might work.
Please ask if you need any more information.
Any help would be massively appreciated.