ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Workbook reference (https://www.excelbanter.com/excel-programming/391605-workbook-reference.html)

[email protected]

Workbook reference
 
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


PCLIVE

Workbook reference
 
Maybe this:

Workbooks(Range("N1").Value).Activate

HTH,
Paul


wrote in message
ups.com...
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




steve_doc

Workbook reference
 
could try
With Sheets("yoursheetname").Range("yourCell").Activate

Or ActiveSheet.Range("yourCell").Activate

Hope this helps

" wrote:

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



Dave Peterson

Workbook reference
 
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)


wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 05:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com