Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to switch to next window and back

I have recorded a macro which works fine but need to change, in effect, one
code line.

What I have right now:
Is a working macro I got Excel [2003] to record, except for the Windows(
"<name").Activate command which has a specific name. Because the name
varies, it needs to move to the 'next' xls window.

Macro:
Sub GetData()
'
' GetData Macro
' Macro recorded 28/11/2006 by Me
'

' Windows( _

"HighSpeed_Service_12756864-HighSpeed_20G(15_Nov_2006-14_Dec_2006)-1.csv"). _
Activate

Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
'
Windows("My Internet Traffic.xls").Activate
Range("A5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub


The macro works perfectly, except next time I get the data (obviously it
contains my internet traffic usage ;-} ) the name of the csv file will be
different so I either need to edit the macro before running it ... or do it
manually which would turn out quicker in that case. But I want to learn VB
macros.

Is there a way to move to the next Window in VB (a replacement for the
Windows( "HighSpeed_Service_etc etc.csv").Activate command) before the Range
thru Selection.Copy commands. I was hoping for something like Windows(
+1).Activate but no such luck & I can't find any documentation on the
Windows(xx) command. Of course then being able to go back one to the
previous active window would be useful too.

Which probably raises another question ... any useful website documenting
the VB command in excel?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How to switch to next window and back

It looks like you would be better of working with Workbook objects instead
of Windows.

Assuming this code will reside in your file "My Internet Traffic.xls", you
can allow yourself/the user to select the .csv file of choice, so the actual
name does not matter. But you will need to know the worksheet name (or index
number).

dim Filename as string
Dim SourceWB as workbook

filename=application.getopenfilename()
set sourcewb=workbooks.open(filename)

with sourcewb.worksheets("Whichever")
.Range("A2", .Range("A2").SpecialCells(xlLastCell)).Copy
end with

Thisworkbook.worksheets("WhicheverHere").Range("A5 ").PasteSpecial
Paste:=xlPasteValues

Note that you do not (normally) have to .Select objects to work with in
Excel.
Check the help for GetOpenFilename to see how to limit the choices to .csv
files and check a valid filename was supplied..

NickHK

"Ludwig" wrote in message
...
I have recorded a macro which works fine but need to change, in effect,

one
code line.

What I have right now:
Is a working macro I got Excel [2003] to record, except for the Windows(
"<name").Activate command which has a specific name. Because the name
varies, it needs to move to the 'next' xls window.

Macro:
Sub GetData()
'
' GetData Macro
' Macro recorded 28/11/2006 by Me
'

' Windows( _


"HighSpeed_Service_12756864-HighSpeed_20G(15_Nov_2006-14_Dec_2006)-1.csv").
_
Activate

Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
'
Windows("My Internet Traffic.xls").Activate
Range("A5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub


The macro works perfectly, except next time I get the data (obviously it
contains my internet traffic usage ;-} ) the name of the csv file will be
different so I either need to edit the macro before running it ... or do

it
manually which would turn out quicker in that case. But I want to learn

VB
macros.

Is there a way to move to the next Window in VB (a replacement for the
Windows( "HighSpeed_Service_etc etc.csv").Activate command) before the

Range
thru Selection.Copy commands. I was hoping for something like Windows(
+1).Activate but no such luck & I can't find any documentation on the
Windows(xx) command. Of course then being able to go back one to the
previous active window would be useful too.

Which probably raises another question ... any useful website documenting
the VB command in excel?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I switch from 1,2,3... back to A,B,C... column reference na C. White Excel Discussion (Misc queries) 7 November 12th 08 05:48 PM
Switch between unknown wbk name grab a value and go back Dale Excel Programming 4 April 19th 06 12:31 AM
How do I switch openoffice back to excel Bill9669 Excel Programming 1 January 18th 06 10:53 PM
Can I switch back to Excel sheet while a form is shown? Ai_Jun_Zhang[_7_] Excel Programming 2 August 31st 05 01:57 AM
how do I switch from one window to another crystal Excel Worksheet Functions 2 June 30th 05 08:11 AM


All times are GMT +1. The time now is 02:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"