Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
when i open an Excell file 3 workbooks open.Why? | Excel Discussion (Misc queries) | |||
When I open Excel, workbooks open automatically. How can I stop t | Excel Discussion (Misc queries) | |||
Workbooks.Open doesn't open file in ThisWorkbook | Excel Programming | |||
Workbooks.Open closes other workbooks | Excel Programming | |||
Workbooks.Open / .Open Text - How do you stop the .xls addition? | Excel Programming |