I have an excel file containing a list of Excel file names in the same directory. Using a macro I got from this forum or another, I am able to open the files but the problem left is I need to open the files with defined worksheet activated.
Here is the macro code:
Sub testopen()
Dim myDir As String, r As Range, fname As String, msg As String
Dim shname As Range
myDir = "C:\Users\Kolokoy\Documents\"
For Each r In Range("A1", Range("A" & Rows.Count).End(xlUp))
fname = Dir(myDir & r.Value)
If fn = "" Then
msg = msg & vbLf & r.Value
Else
With Workbooks.Open(myDir & fname)
End With
End If
Next
If Len(msg) Then
MsgBox "Not found" & msg
End If
End Sub
That code above works in opening the files listed in column A starting from A1. However, In B1 down to B3, I also indicated which sheets to be activated and I cannot seem to figure out how to change the macro so that the files open and the listed sheet names activated as well.
I did a test with 3 files Test1, Test2 and Test3. These blank files exist in My Documents folder along with the "TestControl.xlsm" file which contains the macro code above.
In the TestControl.xlsm file:
A1 = Test1.xlsx
A2 = Test2.xlsx
A3 = Test3.xlsx
B1 = Sheet3
B2 = Sheet2
B3 = Sheet1
Now the macro code above open opens the test files without issues. The problem is, how can I open the files with the listed sheetnames activated.
Thank you
Bookmarks