ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code to switch between workbooks (https://www.excelbanter.com/excel-programming/374803-code-switch-between-workbooks.html)

[email protected]

Code to switch between workbooks
 
Hi there,
I'll try to explain my situation as best as I can - I'm trying to write
some code to switch between workbooks - where the file names are
variables.

Standard code:
Windows("ABC.xls").Activate

How can I replace the "ABC.xls" so that I can switch to any workbook I
define, and not just ABC.xls?

Thanks for any help anyone might be able to provide
Thomas.


Sandy

Code to switch between workbooks
 
Binding that the workbooks are already open you can play around with
this code

Remember that you'll have to use the whole name(including the file
extension, example: Book2.xls

Sub TheSwitch()
Dim MyWkbk As String
MyWkbk = InputBox("Enter the workbook you'd like to activate")
Application.Windows(Result).Activate
End Sub




wrote:
Hi there,
I'll try to explain my situation as best as I can - I'm trying to write
some code to switch between workbooks - where the file names are
variables.

Standard code:
Windows("ABC.xls").Activate

How can I replace the "ABC.xls" so that I can switch to any workbook I
define, and not just ABC.xls?

Thanks for any help anyone might be able to provide
Thomas.



[email protected]

Code to switch between workbooks
 
Sandy,
Thanks for your input. I might be doing something wrong, but I just
copied the code into a blank module, and am getting a "Subscript out of
range" error. I do have the file open that I'm entering in the input
box, and entering the file extension too....

Any ideas?

Thanks for your time and advice!
Thomas.

Sandy wrote:
Binding that the workbooks are already open you can play around with
this code

Remember that you'll have to use the whole name(including the file
extension, example: Book2.xls

Sub TheSwitch()
Dim MyWkbk As String
MyWkbk = InputBox("Enter the workbook you'd like to activate")
Application.Windows(Result).Activate
End Sub




wrote:
Hi there,
I'll try to explain my situation as best as I can - I'm trying to write
some code to switch between workbooks - where the file names are
variables.

Standard code:
Windows("ABC.xls").Activate

How can I replace the "ABC.xls" so that I can switch to any workbook I
define, and not just ABC.xls?

Thanks for any help anyone might be able to provide
Thomas.



Jay

Code to switch between workbooks
 
Try this
Sub TheSwitch()
Dim MyWkbk As String
MyWkbk = InputBox("Enter the workbook you'd like to activate")
Application.Windows(MyWkbk).Activate
End Sub

you were getting error because Result was not defined


" wrote:

Sandy,
Thanks for your input. I might be doing something wrong, but I just
copied the code into a blank module, and am getting a "Subscript out of
range" error. I do have the file open that I'm entering in the input
box, and entering the file extension too....

Any ideas?

Thanks for your time and advice!
Thomas.

Sandy wrote:
Binding that the workbooks are already open you can play around with
this code

Remember that you'll have to use the whole name(including the file
extension, example: Book2.xls

Sub TheSwitch()
Dim MyWkbk As String
MyWkbk = InputBox("Enter the workbook you'd like to activate")
Application.Windows(Result).Activate
End Sub




wrote:
Hi there,
I'll try to explain my situation as best as I can - I'm trying to write
some code to switch between workbooks - where the file names are
variables.

Standard code:
Windows("ABC.xls").Activate

How can I replace the "ABC.xls" so that I can switch to any workbook I
define, and not just ABC.xls?

Thanks for any help anyone might be able to provide
Thomas.





All times are GMT +1. The time now is 09:41 AM.

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