urungus
10-14-2007, 09:17 AM
Hi, I'm a beginning VBA programmer.
I'm writing an Excel Macro that opens a second workbook, and makes a few alterations to it.
At the end of the Macro, I'd like to re-activate the original workbook and sheet that were active when the Macro started.
I recorded a Macro and it gave me this code to reactivate the original sheet:
Windows("mySpreadsheet.xls").Activate
Sheets("Sheet2").Select
I'd like to make it more general, so the code won't break if the name of the original is changed from "mySpreadsheet.xls"
something like
Dim NameOfOriginalWindow As String
Dim NameOfOriginalSheet As String
NameOfOriginalWindow = ??????????????
NameOfOriginalSheet = ??????????????
...
[main body of code]
...
Windows(NameOfOriginalWindow).Activate
Sheets(NameOfOriginalSheet).Select
Thanks for any help.
I'm writing an Excel Macro that opens a second workbook, and makes a few alterations to it.
At the end of the Macro, I'd like to re-activate the original workbook and sheet that were active when the Macro started.
I recorded a Macro and it gave me this code to reactivate the original sheet:
Windows("mySpreadsheet.xls").Activate
Sheets("Sheet2").Select
I'd like to make it more general, so the code won't break if the name of the original is changed from "mySpreadsheet.xls"
something like
Dim NameOfOriginalWindow As String
Dim NameOfOriginalSheet As String
NameOfOriginalWindow = ??????????????
NameOfOriginalSheet = ??????????????
...
[main body of code]
...
Windows(NameOfOriginalWindow).Activate
Sheets(NameOfOriginalSheet).Select
Thanks for any help.