![]() |
Activating an open file with a variable name
I have 2 files open that I need to go back and forth with. File 1 is defined with a variable name oWB. File 2 is called Update.xls When I am in Update.xls and want to go back to oWB, how to I do that? oWB.Activate doesn't seem to work. Any suggestions would be greatly appreciated. Andy |
Activating an open file with a variable name
What do you want to do when you "go back to oWB? oWB.Activate makes the oWB
file the active file. That doesn't mean that it will be on your screen. That depends on your code.. What do you want to happen? HTH Otto "Andyjim" wrote in message ... I have 2 files open that I need to go back and forth with. File 1 is defined with a variable name oWB. File 2 is called Update.xls When I am in Update.xls and want to go back to oWB, how to I do that? oWB.Activate doesn't seem to work. Any suggestions would be greatly appreciated. Andy |
Activating an open file with a variable name
Hi Otto-
Thanks for your quick reply. The macro will do things like copy one of the worksheets to the Update file and similar tasks. It doesn't need to appear on the screen, but needs to get the job done. The reason for file 1 having a variable name is because we don't necessarily know the name of the user's file. Perhaps the explanation below will explain what we trying to do more clearly. At this point, I just need to get back to FIle 1 (with the variable name). In case there would be a different approach, the 1st part of the macro puts the actual name of that file in a cell in file 2 (the Update file). Perhaps we could reference it and activate it using that name, but I didn't succeed doing that either. In an earlier post I referenced this situation: We have put together a small trading system which we plan to send out to users. In order to accommodate future updates, we want to be able to take the name of the user's file (which we don't know for sure) and identify that name so that we eventually save the update as that name. Also, in the process, we will need to be copying history data from the original file to the update file so we need to be able to go back and forth between files. "Otto Moehrbach" wrote: What do you want to do when you "go back to oWB? oWB.Activate makes the oWB file the active file. That doesn't mean that it will be on your screen. That depends on your code.. What do you want to happen? HTH Otto "Andyjim" wrote in message ... I have 2 files open that I need to go back and forth with. File 1 is defined with a variable name oWB. File 2 is called Update.xls When I am in Update.xls and want to go back to oWB, how to I do that? oWB.Activate doesn't seem to work. Any suggestions would be greatly appreciated. Andy |
Activating an open file with a variable name
I'm not sure I understand what you are doing or want to do. You said
earlier that you had set the variable oWB to that "user's file". Exactly how did you do that? Post that line of code that sets that variable. You also say that the name of that file is in some cell in the Update file. If the Update file is the active file, and the cell that holds the user's file name is A1 in sheet "TheSht", and if the user's file is open, you can use something like this: Set oWB=Workbooks(Sheets("TheSht").Range("A1").Value). If the user's file is not open, then you have to have the path to that file, say "ThePath", and use something like: Set oWB = Workbooks.Open(ThePath & Sheets("TheSht").Range("A1").Value) Note that the string ThePath has to have a backslash at the end for this to work. Note that the oWB file will be the active file once it is opened with the above "Open" statement. Otto "Andyjim" wrote in message ... Hi Otto- Thanks for your quick reply. The macro will do things like copy one of the worksheets to the Update file and similar tasks. It doesn't need to appear on the screen, but needs to get the job done. The reason for file 1 having a variable name is because we don't necessarily know the name of the user's file. Perhaps the explanation below will explain what we trying to do more clearly. At this point, I just need to get back to FIle 1 (with the variable name). In case there would be a different approach, the 1st part of the macro puts the actual name of that file in a cell in file 2 (the Update file). Perhaps we could reference it and activate it using that name, but I didn't succeed doing that either. In an earlier post I referenced this situation: We have put together a small trading system which we plan to send out to users. In order to accommodate future updates, we want to be able to take the name of the user's file (which we don't know for sure) and identify that name so that we eventually save the update as that name. Also, in the process, we will need to be copying history data from the original file to the update file so we need to be able to go back and forth between files. "Otto Moehrbach" wrote: What do you want to do when you "go back to oWB? oWB.Activate makes the oWB file the active file. That doesn't mean that it will be on your screen. That depends on your code.. What do you want to happen? HTH Otto "Andyjim" wrote in message ... I have 2 files open that I need to go back and forth with. File 1 is defined with a variable name oWB. File 2 is called Update.xls When I am in Update.xls and want to go back to oWB, how to I do that? oWB.Activate doesn't seem to work. Any suggestions would be greatly appreciated. Andy |
Activating an open file with a variable name
Hi Otto-
Your suggestion "Set oWB=Workbooks(Sheets("TheSht").Range("A1").Value)" worked beautifully. Thank you so much! "Otto Moehrbach" wrote: I'm not sure I understand what you are doing or want to do. You said earlier that you had set the variable oWB to that "user's file". Exactly how did you do that? Post that line of code that sets that variable. You also say that the name of that file is in some cell in the Update file. If the Update file is the active file, and the cell that holds the user's file name is A1 in sheet "TheSht", and if the user's file is open, you can use something like this: Set oWB=Workbooks(Sheets("TheSht").Range("A1").Value). If the user's file is not open, then you have to have the path to that file, say "ThePath", and use something like: Set oWB = Workbooks.Open(ThePath & Sheets("TheSht").Range("A1").Value) Note that the string ThePath has to have a backslash at the end for this to work. Note that the oWB file will be the active file once it is opened with the above "Open" statement. Otto "Andyjim" wrote in message ... Hi Otto- Thanks for your quick reply. The macro will do things like copy one of the worksheets to the Update file and similar tasks. It doesn't need to appear on the screen, but needs to get the job done. The reason for file 1 having a variable name is because we don't necessarily know the name of the user's file. Perhaps the explanation below will explain what we trying to do more clearly. At this point, I just need to get back to FIle 1 (with the variable name). In case there would be a different approach, the 1st part of the macro puts the actual name of that file in a cell in file 2 (the Update file). Perhaps we could reference it and activate it using that name, but I didn't succeed doing that either. In an earlier post I referenced this situation: We have put together a small trading system which we plan to send out to users. In order to accommodate future updates, we want to be able to take the name of the user's file (which we don't know for sure) and identify that name so that we eventually save the update as that name. Also, in the process, we will need to be copying history data from the original file to the update file so we need to be able to go back and forth between files. "Otto Moehrbach" wrote: What do you want to do when you "go back to oWB? oWB.Activate makes the oWB file the active file. That doesn't mean that it will be on your screen. That depends on your code.. What do you want to happen? HTH Otto "Andyjim" wrote in message ... I have 2 files open that I need to go back and forth with. File 1 is defined with a variable name oWB. File 2 is called Update.xls When I am in Update.xls and want to go back to oWB, how to I do that? oWB.Activate doesn't seem to work. Any suggestions would be greatly appreciated. Andy |
All times are GMT +1. The time now is 01:37 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com