+ Reply to Thread
Results 1 to 17 of 17

Necessary to open up one workbook in order to copy information to another workbook?

  1. #1
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Necessary to open up one workbook in order to copy information to another workbook?

    Hi all,

    Just curious if it's at all necessary to physically open a spreadsheet in order to copy information to another workbook? Could one not possibly just list the range and file path you want copied?

    Currently my code is having to open a file, select contents and then paste into another workbook on a specific tab and then close that file. I'd preferably not want the user to see the file physically opening in the toolbar and then closing if even just for the slightest fraction of a second.

    Please Login or Register  to view this content.
    Last edited by Gti182; 11-19-2010 at 11:07 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Necessary to open up one workbook in order to copy information to another workboo

    No, it needs to be opened. Hide the action by switching off ScreenUpdating

    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Re: Necessary to open up one workbook in order to copy information to another workboo

    even with screen updating turned off it still shows the spreadsheets actually opening and closing on the windows taskbar.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Necessary to open up one workbook in order to copy information to another workboo

    You can use ADO

  5. #5
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Re: Necessary to open up one workbook in order to copy information to another workboo

    great, i'll look into that. Seems a lot of code to do something something simple.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Necessary to open up one workbook in order to copy information to another workboo

    That's why I didn't suggest it at first

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Necessary to open up one workbook in order to copy information to another workboo

    And that is why I come up with this one:

    Please Login or Register  to view this content.
    Last edited by snb; 11-19-2010 at 10:17 AM.



  8. #8
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Re: Necessary to open up one workbook in order to copy information to another workboo

    Oh wow i didn't think it was possible with so little code!

    I've tried it out but got a debug error, should probably have put in the exact ranges i'm working with. I've most likely applied the incorrect ranges as i'm not 100% confident i understand what the code is trying to do, any help?

    My actual code:
    Please Login or Register  to view this content.

    Applied snb code:
    Please Login or Register  to view this content.
    Last edited by Gti182; 11-19-2010 at 09:11 AM.

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Necessary to open up one workbook in order to copy information to another workboo

    You are asking Excel to work with 2 different ranges in your modification of the code.

    Try changing the range to the right of the = to match the range to the left of the = sign.

    In other words use "A7:C7" on both sides of the = sign

  10. #10
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Re: Necessary to open up one workbook in order to copy information to another workboo

    ok that makes a little more sense but unfortunately my copy range isn't the same as my paste range?
    Copy range: A9:X65536 in sheet 1, Report X.xls
    Paste range: C7:Z65536 in sheet 5, Reporting model - GM.xls

    i tried a few different variables but i'm debug popping up on this line of code:

    Please Login or Register  to view this content.

  11. #11
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Necessary to open up one workbook in order to copy information to another workboo

    They don't have to be the same range but they do have to be the same size.

    So use Paste range: C7:Z65534 instead of Paste range: C7:Z65536

    Do you really need to copy/paste all those rows?

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Necessary to open up one workbook in order to copy information to another workboo

    As Cutter already said: we try to accommodate your wishes as painstakingly as possible.
    The reason you started this post is to prevent users seeing what is happening in the background. Then we should apply code that does exactly that sort of thing. If we want the code to be as fast as possible, we should preferably avoid the 'copy' method. Instead we write directly from one workbook to the other (avoiding the clipboard).
    To do that we need 2 identically sized ranges. And also I do not believe that you need all rows from A9:X9 downwards to be copied.
    Please Login or Register  to view this content.
    Last edited by snb; 11-19-2010 at 10:17 AM.

  13. #13
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Re: Necessary to open up one workbook in order to copy information to another workboo

    ok didn't think of that, well spotted. Still getting a debug after adjusting my code to:

    Please Login or Register  to view this content.

    What is strange is that i tried it with code in post #10 listing both copy and paste ranges as A1:X65536 to see if it would execute but no luck.

  14. #14
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Re: Necessary to open up one workbook in order to copy information to another workboo

    to answer the other question, rightly said i don't need to copy all the way to last row 65536. I did this as the row length varies on a monthly basis but i'll look into a fix for that if i can crack this query.

    to add:

    I've tried only copying ranges A1:C7 and pasting into sheet 5 A1:C7 just as a test but once again no luck. I'll keep cracking away at it..
    Last edited by Gti182; 11-19-2010 at 10:16 AM.

  15. #15
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Necessary to open up one workbook in order to copy information to another workboo

    A variable approach:

    Please Login or Register  to view this content.
    NB. Do not use values, but Value

  16. #16
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Re: Necessary to open up one workbook in order to copy information to another workboo

    Eureka, both work! Your first solution actually works perfectly but in my code i used Values plural instead of Value singlar.

    This code is really useful and quite a bit quicker i've noticed.

    @snb thanks for both sets of code u are a machine! I think i can possibly incorporate the the ".current region" into my code to fix the variable length problem but i see that it includes headings which are in row 8.

  17. #17
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Necessary to open up one workbook in order to copy information to another workboo

    Values was my fault (in my posts). you were too obedient copying it. . I made a correction in the posts.

+ 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