Activate a workbook

I

IgorM

Hi

I have a macro that enables user to open multiple workbooks or select csv
file which is imported into excel (but not saved as xls file). The path of
each opened file is stored in an array as string (it's 6x6 dimension array).
How can I than use that string (the path) to activate that specific file. So
for instance msPathArray(1,6) stores a string "C:\my files\testfiles.csv"
which is a path to a file that is already opened in excel. How can I
activate that file?

Kind regards
 
G

Gary Keramidas

this is conceptual, since i don't know what your code looks like. so i built
a little test macro, maybe it will help:

Sub test()
Dim mspatharray() As String
Dim fpath As Variant
Dim fname As String
ReDim mspatharray(6, 6)

mspatharray(1, 6) = "C:\my files\testfiles.csv"
fpath = Split(mspatharray(1, 6), "\")
fname = fpath(UBound(fpath))
Worksheets(fname).Activate
End Sub
 
G

Gary Keramidas

sorry, this should be the last line
workbooks(fname).Activate


Sub test()
Dim mspatharray() As String
Dim fpath As Variant
Dim fname As String
ReDim mspatharray(6, 6)

mspatharray(1, 6) = "C:\my files\testfiles.csv"
fpath = Split(mspatharray(1, 6), "\")
fname = fpath(UBound(fpath))
workbooks(fname).Activate
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top