Macro to switch between 2 workbooks

cables

New Member
Joined
Apr 28, 2002
Messages
4
Hi,
I have recorded a macro that copys data from one workbook to another and it works fine for the books it was recorded in. But I need to use the macro in many other books, all with different names.
There must be a line of code that will cause the other open workbook to activate. There will only be two workbooks open and both will have different names each time the macro is needed.
I've searched back through the messages to find a similar question. There are some, but I couldn't quite figure them out. I'm very much a beginner at macros. Using Excel 97.
Thank you for any help.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi cables
It would not be a problem to determine what two books are currently open, the problem is how do we know which book is calling and which book is sending?
Will the procedure only be located in one book?
Give some more details and post your code as well...
Thanks,
Tom
 
Upvote 0
Hi, Here is a sample.
We would handle the workbooks by useing window index.
If 2 workbooks are opened.
An index of Active workbook is 1, another is 2.
Please copy this into a standard module of personal.xls.

<pre>
Sub DataCopy()
Dim rng1 As Range, rng2 As Range
Set rng1 = Application.InputBox("Pls Select the range you want to Copy", Type:=8)
Windows(2).Activate 'Check this Index
Set rng2 = Application.InputBox("Pls Select the range you want to Paste", Type:=8)
rng1.Copy rng2.Item(1)
Set rng1 = Nothing: Set rng2 = Nothing
End Sub
</pre>
 
Upvote 0

Forum statistics

Threads
1,213,492
Messages
6,113,967
Members
448,537
Latest member
Et_Cetera

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top