Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using 2 open workbooks

i am getting subscript out of range error when i am using th
Windows(Filename).Activate command to switch from one open work book t
another....

Is this the correct way? or should i be using another command...?

All i want to do is the following...

Switch to WKBK2
Copy Cells
Switch to WKBK1
Paste Cells
Switch to WKBK2
Copy more cells
Switch to WKBK1
Paster more cells

:

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Using 2 open workbooks

Matt,

to switch between workbooks, I would use:

Workbooks("Book 2").activate

However, for the purposes of your code, there is no need
to switch between them at all, and it'll make your macro
run a whole lot slower if you use it. If I assume that
WKBK1 in your example is the active workbook when you
start, then this code (written on one line, not two) will
copy data from a specified location on the second workbook
and paste it into th efirst without having to select,
activate or switch between anything:

Workbooks("Book2").Sheets("Sheet1").Range("B4:G5") .Copy
destination:= ThisWorkbook.Sheets("Sheet2").range("D4")

Cheers, Pete.

-----Original Message-----
i am getting subscript out of range error when i am using

the
Windows(Filename).Activate command to switch from one

open work book to
another....

Is this the correct way? or should i be using another

command...?

All i want to do is the following...

Switch to WKBK2
Copy Cells
Switch to WKBK1
Paste Cells
Switch to WKBK2
Copy more cells
Switch to WKBK1
Paster more cells

:/

..

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default Using 2 open workbooks

Hi Matt,

The macro recorder uses window ("workbook name").
Use :
Workbooks("your workbook name 1").activate
Copy
Workbooks("your workbook name 2").activate
Paste
This assumes that the corrcet worksheet is also active !!

Or in one line, and avoid screen flashing :
Workbooks("your workbook name 1").Worksheets("your sheet
name").range("A1:B2).copy Workbooks("your workbook name 2").Worksheets("your
sheet name").range("A1:B2)

Shorter is possible if you assign certain objects to mvariables,

Regards,

Jean-Yves



"matt_steer " wrote in message
...
i am getting subscript out of range error when i am using the
Windows(Filename).Activate command to switch from one open work book to
another....

Is this the correct way? or should i be using another command...?

All i want to do is the following...

Switch to WKBK2
Copy Cells
Switch to WKBK1
Paste Cells
Switch to WKBK2
Copy more cells
Switch to WKBK1
Paster more cells

:/


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using 2 open workbooks

This is because you are probably supplying the full file
path in your Windows(Filename).Activate command.

Instead of using Windows("c:\myfilename.xls").Activate,
you need to use Windows("myfilename.xls").Activate.

If you just have the full path, you can use InstrRev
(Win2K or later I think) to search for the last "\" to
parse off the full file path. If you are using an older
version of excel, you have to loop through the file name
until you find the last "\" like:

start_pos = 1
found_pos = InStr(start_pos, filename, "\")
Do While (found_pos < 0)
start_pos = found_pos + 1
found_pos = InStr(start_pos, filename, "\")
Loop

worksheetname = Right(filename, Len(filename) - start_pos
+ 1)

-----Original Message-----
i am getting subscript out of range error when i am

using the
Windows(Filename).Activate command to switch from one

open work book to
another....

Is this the correct way? or should i be using another

command...?

All i want to do is the following...

Switch to WKBK2
Copy Cells
Switch to WKBK1
Paste Cells
Switch to WKBK2
Copy more cells
Switch to WKBK1
Paster more cells

:/


---
Message posted from http://www.ExcelForum.com/

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using 2 open workbooks

still get subscript out of range !!!

I am using the following syntax...

Windows(wkbk1).Activate
Windows(wkbk2).Activate

where wkbk1 is a variable got from user selection

and wkbk2 is a variable assigned to the workbook from where the macr
is running

suggestions???

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using 2 open workbooks

Done it.....

It was the path to the file i was using in the expression....

:

--
Message posted from http://www.ExcelForum.com

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
when i open an Excell file 3 workbooks open.Why? Iain40 Excel Discussion (Misc queries) 2 February 3rd 09 05:04 PM
When I open Excel, workbooks open automatically. How can I stop t Rhealbird Excel Discussion (Misc queries) 2 February 23rd 06 10:08 AM
Workbooks.Open doesn't open file in ThisWorkbook Tomu Excel Programming 0 May 7th 04 10:18 PM
Workbooks.Open closes other workbooks S. Daum Excel Programming 1 August 21st 03 07:47 PM
Workbooks.Open / .Open Text - How do you stop the .xls addition? Dave[_20_] Excel Programming 2 July 31st 03 04:03 AM


All times are GMT +1. The time now is 12:52 PM.

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"