ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   calling windows with variables (https://www.excelbanter.com/excel-programming/305685-calling-windows-variables.html)

Paul

calling windows with variables
 
below is part of a macro which copies information from one
work sheet to another.I switch backwards and forwards
betwen my quote window and my program window several
times.I used to use ActiveWindow.Activate Next but if
there are aother excel windows open it may open the wrong
window.The "myprog" varable work fine and opens the
program window but the "myquote" varaiable doesnt even
though the correct variable is stored(a 4 or 5 digit
number)

myquote = Range("B6")
myprog = Format(Date, "mmmyy")
Workbooks.Open Filename:="\\wxp107475\Brians Docs\Program
Sheets\" & myprog & " Factory Program.xls"
Windows(myquote).Activate'runtime error 9..out of range
'Windows("12000").Activate'the 12000 will change
Sheets("Program").Select
If Range("L13") 0 Then
Range("frames").Sort Key1:=Range("F6"),
Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
Range("frames").Resize(Range("frames").Rows.Count -
Range("M13").Value).Copy
Windows(myprog & " Factory Program").Activate'works fine

Vasant Nanavati

calling windows with variables
 
What is in cell B6 of the active window?

--

Vasant

"Paul" wrote in message
...
below is part of a macro which copies information from one
work sheet to another.I switch backwards and forwards
betwen my quote window and my program window several
times.I used to use ActiveWindow.Activate Next but if
there are aother excel windows open it may open the wrong
window.The "myprog" varable work fine and opens the
program window but the "myquote" varaiable doesnt even
though the correct variable is stored(a 4 or 5 digit
number)

myquote = Range("B6")
myprog = Format(Date, "mmmyy")
Workbooks.Open Filename:="\\wxp107475\Brians Docs\Program
Sheets\" & myprog & " Factory Program.xls"
Windows(myquote).Activate'runtime error 9..out of range
'Windows("12000").Activate'the 12000 will change
Sheets("Program").Select
If Range("L13") 0 Then
Range("frames").Sort Key1:=Range("F6"),
Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
Range("frames").Resize(Range("frames").Rows.Count -
Range("M13").Value).Copy
Windows(myprog & " Factory Program").Activate'works fine




Tom Ogilvy

calling windows with variables
 
Windows(myquote & ".xls").Activate 'runtime

--
Regards,
Tom Ogilvy

"Paul" wrote in message
...
below is part of a macro which copies information from one
work sheet to another.I switch backwards and forwards
betwen my quote window and my program window several
times.I used to use ActiveWindow.Activate Next but if
there are aother excel windows open it may open the wrong
window.The "myprog" varable work fine and opens the
program window but the "myquote" varaiable doesnt even
though the correct variable is stored(a 4 or 5 digit
number)

myquote = Range("B6")
myprog = Format(Date, "mmmyy")
Workbooks.Open Filename:="\\wxp107475\Brians Docs\Program
Sheets\" & myprog & " Factory Program.xls"
Windows(myquote).Activate'runtime error 9..out of range
'Windows("12000").Activate'the 12000 will change
Sheets("Program").Select
If Range("L13") 0 Then
Range("frames").Sort Key1:=Range("F6"),
Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
Range("frames").Resize(Range("frames").Rows.Count -
Range("M13").Value).Copy
Windows(myprog & " Factory Program").Activate'works fine




No Name

calling windows with variables
 
Thanks Tom it works!!!!
-----Original Message-----
Windows(myquote & ".xls").Activate 'runtime

--
Regards,
Tom Ogilvy

"Paul" wrote in message
...
below is part of a macro which copies information from

one
work sheet to another.I switch backwards and forwards
betwen my quote window and my program window several
times.I used to use ActiveWindow.Activate Next but if
there are aother excel windows open it may open the

wrong
window.The "myprog" varable work fine and opens the
program window but the "myquote" varaiable doesnt even
though the correct variable is stored(a 4 or 5 digit
number)

myquote = Range("B6")
myprog = Format(Date, "mmmyy")
Workbooks.Open Filename:="\\wxp107475\Brians

Docs\Program
Sheets\" & myprog & " Factory Program.xls"
Windows(myquote).Activate'runtime error 9..out of range
'Windows("12000").Activate'the 12000 will change
Sheets("Program").Select
If Range("L13") 0 Then
Range("frames").Sort Key1:=Range("F6"),
Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
Range("frames").Resize(Range

("frames").Rows.Count -
Range("M13").Value).Copy
Windows(myprog & " Factory Program").Activate'works fine



.



All times are GMT +1. The time now is 01:21 AM.

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