ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   activate workbook w/unknown name (https://www.excelbanter.com/excel-discussion-misc-queries/37744-activate-workbook-w-unknown-name.html)

Jim Cottrell

activate workbook w/unknown name
 
Can I activate an open workbook without knowing name?

I have a macro that unprotects a workbook, copys and moves a worksheet,
activates the main workbook to re-protect it but I want to leave the user in
the new workbook. I dont know if the name is Book2 or Book3, etc

Sheets("Grid (2)").Move
ThisWorkbook.Activate
Sheets("Cover").Select
Range("C11").Select
ActiveWorkbook.Protect (["password"])
Now I want to activate the single sheet workbook that I moved (Book2 or Book3)


Bob Phillips

When you are in the new workbook, set a workbook object to it

Set oWB = ActiveWorkbook

You can always come back to it using that object variable

--
HTH

Bob Phillips

"Jim Cottrell" wrote in message
...
Can I activate an open workbook without knowing name?

I have a macro that unprotects a workbook, copys and moves a worksheet,
activates the main workbook to re-protect it but I want to leave the user

in
the new workbook. I don't know if the name is Book2 or Book3, etc

Sheets("Grid (2)").Move
ThisWorkbook.Activate
Sheets("Cover").Select
Range("C11").Select
ActiveWorkbook.Protect (["password"])
Now I want to activate the single sheet workbook that I moved (Book2 or

Book3)




Dave Peterson

I like to use a range object and use that:

Dim CurRng as range

set currng = selection
'do lots of stuff
'now go back
application.goto currng



Jim Cottrell wrote:

Can I activate an open workbook without knowing name?

I have a macro that unprotects a workbook, copys and moves a worksheet,
activates the main workbook to re-protect it but I want to leave the user in
the new workbook. I dont know if the name is Book2 or Book3, etc

Sheets("Grid (2)").Move
ThisWorkbook.Activate
Sheets("Cover").Select
Range("C11").Select
ActiveWorkbook.Protect (["password"])
Now I want to activate the single sheet workbook that I moved (Book2 or Book3)


--

Dave Peterson


All times are GMT +1. The time now is 09:20 PM.

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