Workbook reference

  • Thread starter Thread starter mareharbor
  • Start date Start date
M

mareharbor

I have a cell in a workbook that has the path of another workbook in
it. i can succesfully use the path to Open the workbook as such,
"Workbooks.Open Filename:=Range("M1").Value. This works great. Its
actuall the full path with directories. I then have another cell with
just the name of the book to use for referencing it once it is already
open. I just want to activate it using a code like
"Windows("N1").Activate, so i can jump to it. This doesn't work and im
not sure how to do it. I have also tried calling the path a string to
no avail. Any help is great. Thanks
 
could try
With Sheets("yoursheetname").Range("yourCell").Activate

Or ActiveSheet.Range("yourCell").Activate

Hope this helps
 
You could use variables for each of these workbooks.

With just a couple of workbooks, I'd do something like:

dim wkbk1 as workbook
dim wkbk2 as workbook

with worksheets("sheet999")
set wkbk1 = workbooks.open(filename:=.range("m1").value)
set wkbk2 = workbooks.open(filename:=.range("N1").value)
end with

wkbk1.activate
'or
wkbk2.activate

======
If you have a few more workbooks, you may want to build an array of workbooks.

dim myRng as range
dim myCell as range
dim wkbk() as workbook
dim iCtr as long

set myrng = worksheets("sheet999").range("M1:Q1")
redim wkbk(1 to myrng.cells.count)
ictr = 0
for each mycell in myrng.cells
ictr = ictr + 1
set wkbk(ictr) = workbooks.open(filename:=mycell.value)
next mycell

Then you'll have an array of workbooks that you can loop through (if you
wanted).






=======

If you really want to go through the windows collection, you'll have to use just
the filename (drop the drive and path) from the string.

Windows("C:\my documents\excel\book1.xls").activate
will not work
windows("book1.xls").activate
may work (if there is a window with that name)
 

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

Back
Top