Home
Forums
New posts
Search forums
Articles
Latest reviews
Search resources
Members
Current visitors
Newsgroups
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Newsgroups
Microsoft Excel
Microsoft Excel Programming
Looping through file names of a csv and then through other csv
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Matt P, post: 13229135"] Alright my code works for the main part of the script, but I am having problems looping through the files in a folder. It gives me an error saying "File already Open" Not sure exactly why this is happening. Anyone spot where I went wrong, or maybe what is causing the complications? I tested all of the code up until Line 29 to see if everything was being grabbed correctly. Thanks for any help! Heres my code: Sub ReadCSV() Dim intFile As Integer Dim intIndex As Integer Dim strData As String Dim strTemp As String Dim strIndexNum As String Dim arrData As Variant Dim arrIndexNum As Variant Dim lngRow As Long Dim TargetRow As Long Dim Targetsht As Worksheet Dim CurrentCellValue As String MsgBox intFile intFile = FreeFile MsgBox intFile intIndex = FreeFile TargetRow = Range("A1").SpecialCells(xlLastCell).Row + 1 lngRow = TargetRow 'MsgBox lngRow Open "C:\Documents and Settings\User\My Documents\Scanned Pages \Index.csv" For Input As #intIndex Do While Not EOF(intIndex) Line Input #intIndex, strIndexNum arrIndexNum = Split(strIndexNum, ",") MsgBox "C:\Documents and Settings\User\My Documents\Scanned Pages\" & arrIndexNum(0) & "" MsgBox intFile Open "C:\Documents and Settings\User\My Documents\Scanned Pages\" & arrIndexNum(0) & "" For Input As #intFile Do While Not EOF(intFile) Line Input #intFile, strData arrData = Split(strData, ",") 'Set Targetsht = ActiveWorkbook.Worksheets(CurrentCellValue) If IsNumeric(Left(arrData(0), 1)) = False And _ IsNumeric(Right(arrData(0), 1)) = False And _ UCase(arrData(0)) = arrData(0) Then 'TargetRow = ActiveWorkbook.Worksheets.Cells(.Rows.Count, "A").Row + 1 If strTemp <> "" Then Range("A" & lngRow) = strTemp lngRow = lngRow + 1 strTemp = Trim(strData) Else strTemp = strTemp & "," & Trim(strData) End If Loop Close #intFile Loop Close #intIndex Range("A" & lngRow) = strTemp End Sub [/QUOTE]
Verification
Post reply
Home
Forums
Newsgroups
Microsoft Excel
Microsoft Excel Programming
Looping through file names of a csv and then through other csv
Top