Dreamweaver
Well-known member
- Local time
- Today, 00:04
- Joined
- Nov 28, 2005
- Messages
- 2,467
I have 330 excel sheets I need to import rows 77-101 and columm A,B,F,G,H
I have it working upto a point IE. It wont move to next excel row.
I have to do it with the code below as I will be adding a date to each entry in db which is part of the filename which is not a problem.
The results of above are show in attached image
Thanks
I have it working upto a point IE. It wont move to next excel row.
I have to do it with the code below as I will be adding a date to each entry in db which is part of the filename which is not a problem.
Code:
Sub AllExcelFilesInFolder()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String, StrExtShort As String
Dim myExtension As String
Dim R As DAO.Recordset
Dim i As Integer
Dim Ddate As Date
Dim Column
StrExtShort = GetFolderName()
If IsNothing(StrExtShort) Then Exit Sub
Debug.Print StrExtShort
'Target File Extension (must include wildcard "*")
myExtension = "*.xls*"
Set R = CurrentDb.OpenRecordset("SELECT * FROM Chart", dbOpenDynaset, dbAppendOnly)
'Target Path with Ending Extention
myFile = Dir(StrExtShort & "\" & myExtension)
'Loop through each Excel file in folder
Do While myFile <> ""
'Set variable equal to opened workbook
Set wb = Workbooks.Open(FileName:=StrExtShort & "\" & myFile)
Debug.Print myFile
'Ensure Workbook has opened before moving on to next line of code
DoEvents
For Each Column In Range("A77:H101").Columns ' repeat until first empty cell in column A
i = 77
With R
.AddNew ' create a new record
R("TW") = Range("A" & i).Value
R("LW") = Range("B" & i).Value
R("TITLE") = Range("F" & i).Value
R("ARTIST") = Range("G" & i).Value
R("LABEL") = Range("H" & i).Value
R("ChartDate") = Ddate
.Update
End With
i = i + 1
Next
'Ensure Workbook has closed before moving on to next line of code
DoEvents
wb.Close SaveChanges:=False
'Get next file name
myFile = Dir
Loop
End Sub
The results of above are show in attached image
Thanks