malbarghouti1
New Member
- Joined
- Dec 22, 2016
- Messages
- 2
Hello all,
I have a simple code that allows me to chose multiple files, opens them, and also should allow me to do something to the files one file at a time
The problem is that this code once it gets pass the "Workbooks.Open FileName:=var(i)" it opens all the files selected and stops. Even any line after that don't get executed such as the line x = var(i). I use F8 to step through and I can see that the macro just finishes after the "Workbooks.Open FileName:=var(i)" line.
I want to be able to open the files one at a time, do something, close the file and move on to the next.
Thank you for your help
I have a simple code that allows me to chose multiple files, opens them, and also should allow me to do something to the files one file at a time
Code:
Sub test()
Dim var As Variant, i As Integer
Dim x1 As String
var = Application.GetOpenFilename(FileFilter:="Excel files (*.*), *.*", MultiSelect:=True)
For i = 1 To UBound(var)
Workbooks.Open FileName:=var(i)
' i need to do something here such as formatting cells and also closing the file before opening the next
x = var(i)
Next i
End Sub
The problem is that this code once it gets pass the "Workbooks.Open FileName:=var(i)" it opens all the files selected and stops. Even any line after that don't get executed such as the line x = var(i). I use F8 to step through and I can see that the macro just finishes after the "Workbooks.Open FileName:=var(i)" line.
I want to be able to open the files one at a time, do something, close the file and move on to the next.
Thank you for your help