Macro - Documents.Open fileName:= Need help with this command
Hello. I am trying to have a macro open about 300 files that are similarly named in the same directory, to add 3 lines of data. the " * " doesnt seem to work. I am new to making macros and would appreciate any help.
I need help with this line:
Documents.Open fileName:=" .tfw"
I would do this in two steps. First, get a list of all files. Second, process the list of files.
For step one, the basic approach would be like this:
Dim strFile As String
strFile = Dir$("c:\temp\*.doc") 'Get first item in folder
Do While strFile <> "" 'If something was found...
Debug.Print strFile '... do something with it...
strFile = Dir$() '... and get the name of the next file
For putting the data in an array, look up the following help topics in Word VBA help: Using Arrays and Redim Statement.
For going through the array that you have, look up Using For...Next Statements.
Dim strMyFiles() As String
Dim i As Integer
'Fill the array
'Now use the array to open files:
For i = LBound(strMyFiles) To UBound(strMyFiles)
Documents.Open "C:\temp\" & strMyFiles(i)