+ Reply to Thread
Results 1 to 21 of 21

Using macros to paste data values from one workbook to another workbook

  1. #1
    Registered User
    Join Date
    07-15-2012
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2010
    Posts
    12

    Arrow Using macros to paste data values from one workbook to another workbook

    I am trying to write Excel 2007/2010 macros using the Macro recorder that will copy data from one workbook to another workbook using the Copy and Paste Special/Values functions. The "To" worksheet's cell addresses and formats are identical to the "From" worksheet's, so this is very straightforward. I have some experience manually writing macros with if - then - else logic (for example), but this problem is beyond my knowledge. Any help will be appreciated. thanks.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Using macros to paste data values from one workbook to another workbook

    Here's a snippet for pasting formats:

    Please Login or Register  to view this content.
    Just address the ranges prefaced by Sheets(SheetName).Range
    Last edited by xladept; 07-15-2012 at 03:20 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    07-15-2012
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Using macros to paste data values from one workbook to another workbook

    Thanks for your reply. The sheets I'm copying data to are mirror images of the "From" sheets and are already formatted. The "To" sheets are "display only" sheets emailed to those receiving the reports. To avoid them having to deal with any Excel linked data (update/don't update) messages, I want to just copy data values (no formulas or formats) from the "From" sheets to the "To" sheets. I know how to do this from sheet to sheet in the same workbook, but haven't figured out how to do it from workbook to workbook.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Using macros to paste data values from one workbook to another workbook

    Change the paste type to:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-15-2012
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Using macros to paste data values from one workbook to another workbook

    It is the same question, but since I didn't understand the answer; thought I'd be more explicit about what I'll need to understand how to do this. I'm not a VBA programmer, but am good a plagurizing examples.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Using macros to paste data values from one workbook to another workbook

    Try this - (after any appropriate modification):

    Please Login or Register  to view this content.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Using macros to paste data values from one workbook to another workbook

    What was I thinking - you just want to paste the whole thing-right?? Then try this:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-15-2012
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Using macros to paste data values from one workbook to another workbook

    Thanks again for the suggestion. I'm down to one problem. As long as I manually pre-open the "To" sheets before running the macro, the Copy and Paste functions work fine. Unfortunately, asking the user to perform manual pre-open (and later the close) steps is a stretch, so the macro needs to Open and Close the "To" sheets. I haven't figured out how to do this. In another macro I do a "Save as" that works with the following code :

    Please Login or Register  to view this content.
    This is the level of code I need. There is one more wrinkle. Because the "To" sheets are sent to a people who only have Excel 97 - 2003 software, these sheets are in the ".xls" file format. What I need is the exact command syntax to Open and later Close these sheets (with save = yes, and yes it's OK to save in a format different from ".xlsm" options).

    Thanks again for your help and patience.
    Last edited by Cutter; 07-23-2012 at 11:29 AM. Reason: Added code tags

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Using macros to paste data values from one workbook to another workbook

    Perhaps:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    07-15-2012
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Using macros to paste data values from one workbook to another workbook

    I found examples of what I need to Open and Close separate .xls workbooks from a .xlsm workbook in the VBA section and they work fine. Here are the statements I've used:


    Please Login or Register  to view this content.
    The only thing these commands don't do is automate the response to the (these questions are parphrased): 1) "Do you want to save the changes?" and 2) "Is it OKAY to save the sheet in a .xls format and lose functionality (due to Conditional Formatiing)? questions. Is there a way to automate these responses? Thanks.
    Last edited by Cutter; 07-23-2012 at 03:28 PM. Reason: Added code tags

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

    Re: Using macros to paste data values from one workbook to another workbook

    @ FV99

    Please notice that code tags have been added to your post(s). The forum rules (Rule #3) require them so please keep that in mind and add them yourself whenever showing code in any of your future posts.
    Thanks.

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Using macros to paste data values from one workbook to another workbook

    Perhaps:

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    07-15-2012
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Using macros to paste data values from one workbook to another workbook

    I'm happy to add code tags, but can't find the place to do them.

    ---------- Post added at 07:21 PM ---------- Previous post was at 07:18 PM ----------

    This function hides the messages and also selects their "No" options. In this case I need to select their "Yes" options. Thanks, we're getting there.

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

    Re: Using macros to paste data values from one workbook to another workbook

    The method for applying code tags is explained in Rule 3. You can click on the Forum Rules button @ the top of the page to view.

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Using macros to paste data values from one workbook to another workbook

    If you save with the code it won't ask.

    i.e.

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    07-15-2012
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Using macros to paste data values from one workbook to another workbook

    I tried the following and the 1st (e.g. - do you want to save the changes) message did not display and the updates were saved. The 2nd (e.g. - do want to save to the .xls (v. .xlsm) file format because you're using conditional formats) message is still displayed and requires clicking the "Enter" key to complete the Close.

  17. #17
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Using macros to paste data values from one workbook to another workbook

    Are you using this code?

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    07-15-2012
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2010
    Posts
    12

    Post Re: Using macros to paste data values from one workbook to another workbook

    No. I'm trying to save (not save as) and close each file back to its original file name. As mentioned before, this code eliminates the "do you want to save the changes" message and saves the file. It appears that it is during the Close step; that the "do you want to continue" message is displayed and requires manual intervention. Also, I tried the code you suggested and encountered a 1004 error. The following code is what I'm using now:

    Please Login or Register  to view this content.
    Thanks again for your patience and suggestions.
    Last edited by Cutter; 07-26-2012 at 01:06 PM. Reason: Added code tags

  19. #19
    Registered User
    Join Date
    07-15-2012
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Using macros to paste data values from one workbook to another workbook

    The Compatability Check message problem is solved. No need for any macro code. I simply un-checked the Compatabiltiy Checker for each of the sheets with embedded conditional formatting. Problem solved. Thanks everyone for your help. This is my 1st time using the blog. It's great.

  20. #20
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Using macros to paste data values from one workbook to another workbook

    Great, glad you got it resolved.

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

    Re: Using macros to paste data values from one workbook to another workbook

    @ FV99

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  22. #22
    Registered User
    Join Date
    07-15-2012
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Using macros to paste data values from one workbook to another workbook

    I looked for the completed notice and didn't find it. I'm still getting familiar with navigating the blog and will figure it out next time.

+ 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