I need to perform a batch modification of metadata because my father wants to place a "title" in all .jpg images in a folder.
I told him to look into the photos and write down in a Excel spreadsheet the information to write down in order. One cell one file.
So I made the loop to read the spreadsheet but I don't know which file objects I need to use with the .jpg files and which methods can read or write a metadata tag.
MSDN gave no help for this.
A bit of code
Sub seleccionaYmuesrtra()
'in the first column there are the file names.
'in the second column there are the titles written manually
Dim image As ????
???? Set image = New Bitmap("c:\FakePhoto.jpg")
Cells(1, 1).Activate 'I start in the first cell.
Dim contenido, ruta, nombre As String 'some variables
ruta = "C:\imagesToUseinFolder"
While (Not IsEmpty(ActiveCell)) 'this goes down in the first column until the first empty cell.
nombre = ruta & ActiveCell.Value & ".jpg"
contenido = ActiveCell.Offset(1, 0).Value
'------------------------------------
'HERE GOES THE ACTION I DON'T KNOW
...
'------------------------------------
ActiveCell.Offset(1, 0).Activate 'MOVE ONE DOWN
Wend
End Sub
I'm working in my laptop with windows7 but I think it should work in my parents desktop computer with XP.
Thank you for your time, I hope that was not answered yet.
You could try invoking a tool as a command-line command (if you need help invoking, see Execute a command in command prompt using excel VBA)
Exiftool is a good free, standalone executable that should do what you want:
http://www.sno.phy.queensu.ca/~phil/exiftool/
Related
I have multiple .txt files in the form of
Name1|number1
Name2|number2
Name3|number3
(...)
And I would need to transpose them to look like:
Name1|Name2|Name3|(...)
Number1|Number2|Number3|(...)
This is easy enough to do for a single file in excel, but I would need a way to do this in multiple files in a folder. Since Notepad++ allows finding and replacing for multiple files, I would like to know if there is a way to achieve this somewhat automatically.
While all files have the same pattern (two columns), not all of them have the same number of rows.
I have tried the following aproaches using Notepad++:
Replacing | for a carriage return to have everything in a single column, in hopes to somehow group all numbers, move them to the bottom and reorganize.
Repeat the whole text below using a symbol to separate both copies (find [\s\S]*.*, replace with \0\n%\n\0), in an attempt to delete all numbers above and all names| below to finally reorganize. Also got stuck in the middle.
As you can see, my Regex knowledge is extremely limted, even using Regex101. I don't know if this is easy or hard to achieve, I simply cannot find the solution by myself after several hours.
What can I do?
Thanks for your patience in advance.
Thanks for the answer. I thought about macros, but all my searches ended up mentioning Power Query. It is a business oriented add-in, and I would rarely need it, so I was't willing unless there was no choice (and I also happen to like Notepad++ quite a bit, that might have blinded me).
However, I was googling the wrong question; as soon as I rephrased my search, I found everything I needed. It is extremely simple to achieve this using excel VBA.
Source:
Apply a macro to all files in prompted folder
I basically recorded a macro to transpose the 2 columns into rows and deleted the original columns, so that only the transposed rows would show. Then, I copied that macro and pasted it inside another one (see source) which loops through all files in a folder (and added another piece of code to automatically save and close the files).
With this new macro, there is no need to open any file; simply open excel, insert the macro and run it. Voilà.
Final macro:
Sub LoopThroughFiles()
Dim xFd As FileDialog
Dim xFdItem As Variant
Dim xFileName As String
Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
If xFd.Show = -1 Then
xFdItem = xFd.SelectedItems(1) & Application.PathSeparator
xFileName = Dir(xFdItem & "*.txt*")
Do While xFileName <> ""
With Workbooks.Open(xFdItem & xFileName)
'Start of transpose code
Range("A1").CurrentRegion.Select
Selection.Copy
Range("C1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Columns("A:B").Delete
Range("A1").Select
Application.CutCopyMode = False
'End of transpose code
'Save and close
ActiveWorkbook.Close SaveChanges:=True
'End of save and close
End With
xFileName = Dir
Loop
End If
End Sub
It was so simple I feel stupid now, sorry to all who had to read the post and rolled their eyes.
I am creating a vba For loop to cycle through cells in a range and creating a hyperlink to file folders based on the text within the cell. See below:
Set rng = Worksheets("Sheet1").Range("A1:A100")
For Each cell In rng
address1 = "C:\Users\Desktop\Tests\Comm Review\Item #" &
cell.Text
If Not IsEmpty(cell) Then
Worksheets("Sheet1").Hyperlinks.Add Anchor:=cell, Address:=address1, TextToDisplay:=cell.Text
End If
Next cell
The cell value will be something like 1001.T0502 and the actual folder name that I am linking to will be Item #1001.T0502. So in my address1 variable i create the path to the folder.
However, when I do this it creates the path with everything but #1001.T0502 and ends up stopping at "\Item". If I were to drop the number sign(#) though it includes the number and ends up being Item 1001.T0502. For some reason the number sign stops it from making the correct path. What am I missing here? There are already 200 folders with the number sign in the folder name so going back now and taking it out would be too much work.
Any help would be appreciated. Thanks!
You cannot use a pound character in a file name for a hyperlink in an Office program. See official Microsoft documentation here:
https://support.microsoft.com/en-us/help/202261/you-cannot-use-a-pound-character-in-a-file-name-for-a-hyperlink-in-an
Seems totally wacko if you ask me, but alas, I think you're trying to solve an unsolvable problem.
But, fear not, I did think of a potential work around. Instead of making the cells actual hyperlinks, you could just recolor the cell to blue with an underline and then use this little trick to capture when the cell is selected and open Windows Explorer to the corresponding file path.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("A1:A100")) Is Nothing Then
Shell "explorer ""C:\Users\Desktop\Tests\Comm Review\Item #" & Target.Value & """", vbNormalFocus
End If
End If
End Sub
The only downside I can see here is that selecting the cell with the arrow keys also opens the corresponding folder. There may be a work around to that, but I don't have time at the moment to research it.
I hope this helps!
I am working on a spreadsheet in which I will keep track of everything that my department 3D prints. I have 3 folders full of one thing each for every part I print: a CAD file, an STL file, and a job folder; all of these contain the same part name which is entered into a cell in the spreadsheet and used for finding all of the files/folders. I like to have my spreadsheet hyperlinked so that I can easily open up any of the three by simply navigating to that part in my spreadsheet.
Now I have the following section of code which takes the name of the printed part from column D, and finds the matching STL in my STL folder, and then hyperlinks it into column U.
For i = 4 To Range("D" & Rows.Count).End(xlUp).Row
'follow through all entries in column D
'--STL------------------------------------------------------------------------------------------------------
If (Len(Cells(i, 4)) > 1) Then
If (Len(Cells(i, 21)) = 0) Then
strFile = Dir$(path5w & Cells(i, 4) & "*.stl")
If (Len(strFile) > 1) Then
Cells(i, 21).Hyperlinks.Add Cells(i, 21), path5 & strFile, TextToDisplay:="STL"
Else
'No file was found that matches so do nothing
End If
Else
'Already hyperlinked, skip this cell
End If
Else
'Not a valid Name, do nothing
End If
Next
End Sub
I simply copied this chunk of code again and switched the path and switched .STL the extension for my CAD files, and it works great for both of those, but I am getting stuck on the job folders... I have no idea how to get my code to find a folder instead of a file.
I have tried playing around with FileSystemObjects, but I don't fully understand how to use them, and all I can find is an example of how to list every folder inside a folder, and not how to actually search for a specific folder.
I also looked at this example: VBA to find multiple files but, again, I run into the problem of not understanding how to use this to search for a folder, rather than listing all folders.
So to help be more clear I will give an example. Lets say I process Part123.stl, when I want to save this, it will create a folder ssys_Part123 and I will save that in my folder named Job Folders. Now I want my program to check cell D4 which says Part123, then navigate to Job Folders, find the folder named ssys_Part123 and hyperlink that folder into V4.
I still don't have a very firm grasp of coding, so any help is always greatly appreciated.
If the folder name is always going to be ssys_[PartName] then you should be able to just concact the strings to link to the folder instead of trying to look up the folder name.
I currently use a spreadsheet where I need to manually hyperlink 4 separate files in each row which include important information for referencing (3 are PDFs and 1 is an excel spreadsheet). Each row is full of information for a specific order number, which is conveniently part of each file that I need to hyperlink. Each of the 4 types of documents I would like to hyperlink into my excel sheet are also all packed into 4 folders path1, path2, path3, and path4, and they have their own column in the spreadsheet. Each folder will only contain one file with the order number.
I tried to automate this in excel only, using these formulas in the 4 columns:
K2 =IF(ISBLANK(C2)," ",HYPERLINK("J:path1\"&C2&".pdf",C2))
L2 =IF(ISBLANK(C2)," ",HYPERLINK("J:path2\"&C2&".pdf",C2))
M2 =IF(ISBLANK(C2)," ",HYPERLINK("J:path3\"&C2&".xlsx",C2))
N2 =IF(ISBLANK(C2)," ",HYPERLINK("J:path4\"&C2&".pdf",C2))
The formula references cell C2 which is the order number, and it fills the path with that number, which works great for the files which are consistently named. It also leaves the cell blank if there is no order number, because it happens sometimes and I need the function to not freak out when there is nothing there. The problem comes when I run into the file names that have other things tacked on the end such as a date. My formula is incapable of hyperlinking a file unless I give it the exact path to begin with.
I am wondering if anyone knows if excel is even capable of finding a file in a folder when only given part of the file name.
If there is not a way to do this in excel, I was hoping there may be a way to do this with VBA. I did some searching and found the Application.FileSearch feature in VBA, but it says "Object doesn't support this action." when I try to call it. (Which from a simple google search that seems to be the error due to Application.FileSearch not existing in excel 2007, but I am running 2013, so I'm not sure why this is happening)
I have a very novice understanding of VBA, so I am trying to slowly learn on the side. If anyone could help me come up with a code that would allow me to reference a cell, and find files containing that name so that I could print that path to a different cell, I would greatly appreciate your help.
Something like this should work (or at least point you down a path to investigate).
Sub HyperlinkFiles()
Dim strFile As String
strFile = Dir$("J:\path1\*" & Sheet1.Range("C2") & "*.pdf")
If (Len(strFile) > 1) Then
Sheet1.Range("k2").Hyperlinks.Add Sheet1.Range("k2"), strFile
Else
'No file was found that match so do nothing
'However, you could link to the folder to make manually searching easier
'Sheet1.Range("k2").Hyperlinks.Add Sheet1.Range("k2"), "J:\Path1"
End If
strFile = Dir$("J:\path2\*" & Sheet1.Range("C2") & "*.pdf")
If (Len(strFile) > 1) Then
Sheet1.Range("L2").Hyperlinks.Add Sheet1.Range("L2"), strFile
Else
'No file was found that match so do nothing
End If
strFile = Dir$("J:\path3\*" & Sheet1.Range("C2") & "*.xlsx")
If (Len(strFile) > 1) Then
Sheet1.Range("M2").Hyperlinks.Add Sheet1.Range("M2"), strFile
Else
'No file was found that match so do nothing
End If
End Sub
The caveat with this code is when there are 2 or more files that match the search pattern. For example, suppose cell C2 contains Stack and you have 2 files named stackoverflow.pdf and stackexchange.pdf. Which "stack" file do you want?
I am really desperate to have your help to get this code fixed before end of today because my boss wants it to be done. I could not figure out how to set loop to read multiple files in .txt then import special lines to excel!! Please help me.
Sub ImportFile()
Dim J As Long, K As Long
Close #1
Open "C:\TestFolder\TestFile.txt" For Input As #1
For Each f In A$
J = 1
K = 0
Do While Not EOF(1)
K = K + 1
Line Input #1, TextLine
If K = 22 Then
ws.Range("a1").Cells(J, 2) = Mid(TextLine, 20, 16)
End If
If K > 69 And K < 77 Then
ws.Range("a2").Cells(J, 2) = Mid(TextLine, 1, 9)
J = J + 1
End If
Loop
Next
You say: I have looked through all questions and noticed that most of all questions got answers with script created?.. i am little confusion about stackoverflow's purpose to have this website for us? provide us scripts if we feel trap or trouble?
There is a lot in this answer some of which will not make sense on first reading. I believe eveything will make sense after a little study. You may have to look up some VBA statements to understand what they do but I have tried to avoid anything too complicated.
There are many people answering questions so you will not get a consistent response to questions.
If your question is especially interesting to someone or if they have some suitable code to hand, they may give you a complete answer when they should not according to this site’s philosophy.
If you use a phrase that annoys people, you will be ignored or get rude replies. “Can I do X?” annoys many here. You are new to the site; how could you know you were being offensive?
We are not here to provide free code to anyone that wants it. This site is about programmers helping other programmers to improve. You are explicitly required by the site rules to have a minimal understanding of how to solve your problem. Some answerers will take mercy and ignore this rule; most will not. We are supposed to help you write your own new code or improve your existing code; not write it for you.
You have asked three questions within a day which seem to me to be different aspects of the same problem. But it does not appear you have understood how to solve the first part of your problem or even that your problem has parts.
I appreciate the difficulties of having a boss demanding you solve a problem NOW that is totally outside your skill set. Because there is so much available on the internet, your boss expects everything to be available. You cannot find the exact solution to his problem so it is your fault for not trying hard enough. No it is not your fault. This is a unique problem so why would someone have coded and posted a solution for it? I will be diplomatic and not say what I think of your boss.
My understanding of your problem is:
You have about 100 text files each containing some information you wish to extract.
The information to be extracted is lines 67 to 76.
You want to collect this information into a worksheet. I do not think you have said if this worksheet is in an existing workbook or if the new information is to be added below previously extracted information in an existing worksheet.
You do not say how the information is to be arranged. Do you want the 10 lines from each file spread along a single worksheet row or do you want one file line per worksheet row?
My understanding is that you have not got the solution to step 1 yet. There is little point asking about extracting lines 67 to 76 if you do not know how to get all the files you want to read. So let us try to solve part 1.
I tried searching StackOverflow and the internet for relevant code. I got the best response for “How to read all workbooks in a folder with VBA” but it would be difficult (impossible?) for a novice to separate the relevant information from the noise.
Having no or almost no knowledge of VBA makes it very difficult to recognise what you want when you find it. The internet has many “Excel VBA tutorials”. A large library or bookshop will have a computer section with a shelf full of how-to books some of which will cover VBA. Please invest some time in background study. That investment will repay itself very quickly.
A question like this might have produced a useful response:
I have a folder containing 100 text files which I want to process one by one. I am sure there are functions that will help but I cannot find them.
This question is very contained and I believe someone would give a useful answer. Do not forget to accept that answer because that gives points and reputation to the answerer. You want to gain a reputation as someone who accepts answers so people want to answer your questions. As soon as one question is answered and accepted you can ask another. There is no limit on the number of questions you can ask per day.
You could also try opening the VBA editor, selecting Help then Microsoft Visual Basic Documentation then Visual Basic Language Reference then Functions. Under that are all the available VBA functions listed in alphabetic order. Most are of no relevance to your current problem. The one you want is Dir or Dir$. They appear identical but Dir$ is marginally more efficient.
I do not know how a beginner could find the other way of getting a list of files in a folder. You need to look at the Files Property of the Folder Object. If you search for VBA Help for Files Property you will get a long list of results. One is Files Property (Visual Basic for Applications). Selecting that will give you a nice piece of relevant code.
VBA Help is a dictionary. If you do not know a word exists and you do not know approximately how to spell it, you will not find that word. You can have a quick look at each function, method and property and decide if any look interesting. Some swear by that approach but I find a good book a better approach for me. Your choice.
The Dir function is the older and easier approach. However, you will need File System Objects for the next part of the problem so I will use that approach.
Create a workbook in the folder containing the text files if you do not already have a suitable workbook. You do not have to have the workbook in the same folder but it is easier if you do and the macro below assumes they are in the same folder.
Open the VB Editor, create a new module and copy the code below to it.
Option Explicit
Sub Test1()
Dim FileSysObj As Object
Dim FolderObj As Object
Dim FileColl As Object
Dim FileObj As Object
Dim PathSearch As String
' This assumes the text files are in the same folder as the workbook holding the macro.
' Use PathSearch = "C:\ ..." if you would rather have the files in a different folder.
PathSearch = ActiveWorkbook.Path
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set FolderObj = FileSysObj.getfolder(PathSearch)
Set FileColl = FolderObj.Files
For Each FileObj In FileColl
With FileObj
If LCase(Right(.Name, 4)) = ".txt" Then
Debug.Print .Name & " " & .DateCreated & " " & .Size & " bytes"
End If
End With
Next
End Sub
This macro displays a list of every file with an extension of “.txt” or “.TXT” in the folder PathSearch. I have included the creation date and the size, which you do not need, to show there are other properties available. This macro shows how to find the names of all the text files in a folder. This is the solution to the first part of your requirement.
Part 2 of your requirement is to open each file, extract selected contents and close the file.
There are two distinct approaches to handling text files. The older approach uses file numbers. For example the open statement is:
Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength]
The newer approach uses file objects:
object.OpenAsTextStream([iomode, [format]])
I will use the second approach because I want to use the ReadAll method. This is very convenient providing the file is not too large. You can read large files with ReadAll if you have enough free memory but if you only want a few lines near the beginning, it is not very efficient.
Once you know how to use File System Objects to access folders and file lists, using them to open and access files is relatively easy. If you were trying to get your solution by asking a series of questions, you should try writing your own code for part 2. If your code fails, you can post a question that seeks help with fixing your code. That is the type of question that is most quickly answered. Your error was probably a simple syntax error that an experienced programmer will spot instantly. I am going to give you my solution to part 2.
Copy and paste Sub Test1 and amend its name to create Test2.
You will need some more variables so add this at the top of Test2:
Dim File As Object
Dim FileAll As String
Dim FileLine() As String
In Test1 I used a With statement:
With FileObj
If LCase(Right(.Name, 4)) = ".txt" Then
Debug.Print .Name & " " & .DateCreated & " " & .Size & " bytes"
End If
End With
This was easier than writing the equivalent without a With statment:
If LCase(Right(FileObj.Name, 4)) = ".txt" Then
Debug.Print FileObj.Name & " " & FileObj.DateCreated & " " & FileObj.Size & " bytes"
End If
For my Test2 it would probably still be easier to use a With statement but it will not be easier for Test3 so I will drop the With statement now.
Replace For Each FileObj In FileColl to Next with:
For Each FileObj In FileColl
If LCase(Right(FileObj.Name, 4)) = ".txt" Then
Set File = FileObj.OpenAsTextStream(1) ' 1 means open in read mode
FileAll = File.ReadAll
File.Close
FileLine = Split(FileAll, vbCr & vbLf)
Debug.Print FileObj.Name & " " & FileLine(0)
Debug.Print FileObj.Name & " " & FileLine(1)
End If
Next
With Test1, I identify each text file in a folder and prove I have done so by displaying each file's name. With Test2, I have extended the macro a little. It now:
Opens each file.
Reads its contents in a string.
Closes the file.
Uses function Split to break that string into lines. This assumes these files use CR LF as line breaks which is the standard for Windows. If this assumption is false, FileLine(0) will be the entire file and there will be no FileLine(1). The next most likely line break is LF alone.
Displays the first two lines of the file to demonstrate the macro has worked.
If experimentation does not help you find the correct line break character or string, you could ask a question like:
I have read a text file into a string and want to split it into lines. I have tried:
FileLine = Split(FileAll, vbCr & vbLf)
FileLine = Split(FileAll, vbLf)
but neither works. Please suggest how I can determine the line break string.
If I saw this question, I would suggest:
Debug.Print Replace(Replace(Mid(FileAll, 1, 200), vbCr, "{cr}"), vbLf, "{lf}")
This converts CR and LF into printable strings. It is most unlikely the line break is not some combination of CR and LF. You could add this statement to Test2 to see what it outputs. If that failed for you, I would come back with a more complicated diagnostic routine.
Debug.Print is a very easy way of showing a macro is working (or not). Its one obvious limitation is that the Immediate Window has a limited size and early lines can be lost to make way for later lines. I am not sure what the limit is but suspect it is less than 200. In this particular case, seeing the last 200 or so lines will be adequate demonstration of success. In other cases, this will not be adequate. I will add a possible solution to my next "answer".
We now have a macro that solves the first part 1 of your requirement and part of part 2.
I would expect, you to be able to complete part 2 without asking a question. Since all you need is a simple For-Loop, I believe you would find it difficult to construct a question that anyone would take seriously.
I would expect you to realise you need a new variable:
Dim InxLine As Long
and to replace the two Debug.Print statements with:
For InxLine = 66 To 75
Debug.Print FileObj.Name & " " & FileLine(InxLine)
Next
I would have expected you to have noticed that the first line of the file was in FileLine(0) which why I have output lines 66 to 75.
With 10 lines per file, there is no possibility that all could fit into the Immediate Window. As I said, this does not really matter in this case but might in another. Probably the best choice is to have a diagnostic file. At the beginning of the macro create a text file, write diagnostic information to during the run and then close it. An easier technique would be to add another variable:
Dim Count as Long
and replace the For-Loop above with:
For InxLine = 66 To 75
Debug.Print FileObj.Name & " " & FileLine(InxLine)
Count = Count + 1
Next
If Count > 100 Then
Debug.Assert False
Count = 0
End If
Debug.Assert is a very useful diagnostic aid. Normal use might be Debug.Assert myVar > 0. myVar is being corrupted somewhere within my macro but I cannot find where. I place Debug.Assert myVar >= 0 throught my macro, and it will stop as soon as myVar has a negative value allowing me to investigate. With Debug.Assert False the macro will always stop. This means that every 100 lines or so, the macro will stop to allow me to examine the Immediate Window. Clicking F5 will restart the macro.
With this latest change, the macro outputs the lines of interest to the Immediate Window to prove that it can locate the lines of interest.
The final step is to output the lines of interest to a worksheet. As I said you did not say what worksheet or how the lines are to be organised. There are many answers that show you how to create a new workbook or open an existing workbook. If an existing workbook there are answers showing how to find the bottom of any existing data within a worksheet so the new data can be added. Because of this, I will do the easiest which is to clear worksheet "Sheet1" of the current workbook and write the data to it.
Add two new variables:
Dim ColCrnt As Long
Dim RowCrnt As Long
Near the top of the macro add:
With Worksheets("Sheet1")
' Clear the worksheet
.Cells.EntireRow.Delete
' Create a heading row
RowCrnt = 1
ColCrnt = 1
.Cells(RowCrnt, ColCrnt).Value = "Filename"
For ColCrnt = 2 To 11
.Cells(RowCrnt, ColCrnt).Value = "Line " & ColCrnt + 65
Next
.Range("A1:K1").Font.Bold = True
RowCrnt = 2
End With
Replace:
For InxLine = 66 To 75
Debug.Print FileObj.Name & " " & FileLine(InxLine)
Next
with
With Worksheets("Sheet1")
.Cells(RowCrnt, 1).Value = FileObj.Name
For ColCrnt = 2 To 11
.Cells(RowCrnt, ColCrnt).Value = FileLine(ColCrnt + 64)
Next
End With
RowCrnt = RowCrnt + 1
At the bottom add:
With Worksheets("Sheet1")
.Columns.AutoFit
End With
When you run this macro it should do approximately what you seek.
Summary
You must get a general grounding in VBA. Without that, your attempts to construct a macro from bits of script on this or other sites will be like construction a letter in a language you do not know from bits of text in that language.
I have tried to show the importance of breaking your requirement down into little steps. Getting answers to little questions is usually easy.
From the pieces of code you find on the internet or within Visual Basic Help construct a sequence of macros:
Macro 1 proves you can achieve step 1 of your requirements.
Macro 2 proves you can achieve steps 1 and 2 of your requirements.
Macro 3 proves you can achieve steps 1, 2 and 3 of your requirements.
: :
Macro n meets your requirements.
I hope this has helped. Good luck.
There are several issues right off the bat with your code, 1 is not a valid variable name (identifier). Variable names cannot start with a number or a variety of special characters and cannot contain spaces. You are also missing the End Sub in the example code, however I believe you have that already in your IDE as VBA won't even compile without it. I have written a piece of code below that satisfies the requirement of being able to read the contents of a file line by line. If you need to open a second file, you need to simply need to duplicate the code starting at Open and ending with Close #A.
Sub ImportFile()
Dim J As Long, K As Long
Dim FileNum As Integer
Dim A As String
A = FreeFile()
Open "C:\Users\UserName\Desktop\movies" For Input As #A
While Not EOF(A)
Line Input #A, FileLine
Wend
Close #A
End Sub
StackOverflow isn't typically the place to get your code written for you, but we're glad to help you sort out specific issues. If you have more questions once you have been able to read in each file line by line, you should post another question with the specific problem and your attempts to solve it.