Possibly, the invoice period would always have to exist in the same place or be parsable (like its the 5 item in a row). This begins to get a bit difficult. Here is how I would handle this. I use Access to open what I'll refer to as a MacroFile (just a helper workbook with macros in it) and the source file/files. Then I have access run the macro from the MacroFile against the source file.
Code:
This is an example of that:
Set objExcel = CreateObject("Excel.Application")
objExcel.DisplayAlerts = False
Set objMacroWorkbook = objExcel.workbooks.Open(CurrentProject.Path & "\Format Alignment Workbook.xlsm")
Set objWorkbook = objExcel.workbooks.Open(ExportMasterListFile)
objExcel.Visible = True
objExcel.Application.Run "'Format Alignment Workbook.xlsm'!wirereports"
objWorkbook.Close False
objMacroWorkbook.Close
objExcel.quit
The macro would select the first row or specific cell and write it to a new workbook called temp.xls. It would then delete those rows. You need to delete those so the upload will upload correctly. Personally I use a TransferSpreadSheet command. So you would read the first line, create a new file, delete the line, save the file,close it, use a TransferSpreadSheet to import the file, import the temp file (if you have to parse out text). If you copied just one cell we can get fancier. When you paste that cell to a new workbook we can name the workbook the name of that cell. Then we can just read the name of that file and import just the name and us and update query. Then we loop and do it all over again if you're reading multiple file or if you just gave them one file option you are done.
This is an example of editing a workbook and saving it as a temp file. You don't see the TransferSpreadSheet command because it is in the Access function. This is one of my Excel Macros:
Code:
Public Sub Combine()
Call WMVCEdit
Call OpticalEdit
Dim J As Integer
On Error Resume Next
Sheets(1).Select
Worksheets.Add ' add a sheet in first place
Sheets(1).Name = "Combined"
Sheets("WM VC").Activate ' make the sheet active
Selection.CurrentRegion.Select ' select all cells in this sheets
Selection.Copy
Sheets("Combined").Range("A65536").End(xlUp).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Sheets("Sam's Optical").Activate ' make the sheet active
Range("A1").Select
Selection.CurrentRegion.Select ' select all cells in this sheets
' select all lines except title
Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
Selection.Copy
Sheets("Combined").Range("A65536").End(xlUp).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Worksheets("Combined").Copy
Set wb = ActiveWorkbook
wb.SaveAs Workbooks(2).Path & "\Temp.csv", FileFormat:=6
wb.Close
End Sub
This is kind of how I import. You see I run a TransferText command in this example and then I run an UPDATE query to update fields with a date based on the name of the file I imported. I only update NULL values. I then delete the temporary file I created and add the filename I imported to a table
'Import the .csv file to the Applied Report table
DoCmd.TransferText acImportDelim, "spec with concatenate", "Applied Report", strPath & "temp.csv", True
Code:
'All the filename date to the GroupingDate field
strSQL = "UPDATE [Applied Report] SET GroupingDate = '" _
& strProperName _
& "' WHERE GroupingDate IS NULL;"
CurrentDb.Execute strSQL
'Delete the .csv file that was created
Kill strPath & "temp.csv"
strDate = FileDateTime(strPath & strFile)
rs.AddNew
'to save the full path using strPath & strFile
'save only the filename
rs!FileName = strFile
rs!FileDate = strDate
rs!UploadedDate = Now()
rs.Update
Note these examples don't exactly go together they are just parts of a very big database I wrote.