+ Reply to Thread
Results 1 to 10 of 10

Cannot paste into an non-active workbook

  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    204

    Cannot paste into an non-active workbook

    Dear All,

    I am trying to paste from an active workbook(2) into an open workbook(1)

    I first tried it with activiating workbook(1) and then succesfully pasted. Then I tried it without activating workbook(1) which failed.

    I would appreciate knowing if this is even possible and if so how?

    My attempt at this is in the workbook(2) macro

    Thanks John
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Cannot paste into an non-active workbook

    Yes - it is possible, I would do it like this:

    Please Login or Register  to view this content.
    I think you have a problem with the way you reference the range 'copytobook1' in your code when the sheet is not activated.

  3. #3
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    204

    Re: Cannot paste into an non-active workbook

    Thank you for your response.

    Actually, "This my test file 1.xlsx" should be a in a range name single cell in "This my test file 2.xlsx" and the same applies for CopytoBook1 (e.g. cell Z1)

    How to do this?

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Cannot paste into an non-active workbook

    Sorry, not sure I understand - if you mean you have the names of the sheets and ranges in other cells:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    204

    Re: Cannot paste into an non-active workbook

    Sorry for the confusion.

    What I mean is the following:

    1) In workbook "This my test file 2.xlsx" i have 2 named ranges.
    2) Named_Range_1 contains the name of a workbook (e.g. "This my test file 1.xlsx")
    3) Named_Range_2 contains a range (e.g. A1:A120).
    4) Both Named_Range_1 and Named Range_2 can be changed in "This my test file 2.xlsx".
    5) If may Macro has hard coded data then I cannot change the namae of the workbook or the range without editing the code.
    6) So I am trying to make them variables so that the macro code doe snot need to be changed.

    Thanks alot for your help.

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Cannot paste into an non-active workbook

    Sub Macro2()
    Range("copyme").Copy Workbooks(Range("Named_Range_1")).Sheets("sheet1").Range(Range("Named_Range_2"))

    Note - This depends on the worksheet being called "sheet1" in all cases
    End Sub

  7. #7
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    204

    Re: Cannot paste into an non-active workbook

    Thanks alot Yudlugar, much appreciated.

    Have a nice day, John.

  8. #8
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    204

    Re: Cannot paste into an non-active workbook

    Sorry,

    Still does not work, I get a an error type mismatch.

    Also how to paste formats?

    Thanks John

  9. #9
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Cannot paste into an non-active workbook

    Ah yeah, I missed something:
    Please Login or Register  to view this content.
    I tested that one and should be ok. You want to paste only formats? that would be:
    Please Login or Register  to view this content.
    Otherwise the formats should be included in the first code

  10. #10
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    204

    Re: Cannot paste into an non-active workbook

    That worked, thanks alot!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1