Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Macro to switch between 2 workbooks

  1. #1
    New Member
    Join Date
    Apr 2002
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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.

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  3. #3
    MrExcel MVP
    Colo's Avatar
    Join Date
    Mar 2002
    Location
    Kobe, Japan
    Posts
    1,456
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    2 Thread(s)

    Default

    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.


    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

    Hope this helps + pen pineapple apple pen!

    Masaru Kaji aka Colo - cellmasters.net

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •