+ Reply to Thread
Results 1 to 8 of 8

copy entire worksheet to current workbook

  1. #1
    Registered User
    Join Date
    09-17-2008
    Location
    UK
    Posts
    3

    copy entire worksheet to current workbook

    Hi, I am new to VBA and I would to know if any of you have a macro that I can user to copy an entire worksheet from a workbook (in a specified directory) to the current workbook using VBA? - Thanks for your help.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello AJHWilliams,

    Welcome to the Forum!

    If this a one time event, you don't need VBA to do this.

    1) Have both workbooks open.
    2) Activate the sheet you want to copy
    3) On the main menu click Edit
    4) Select Move or Copy Sheet...
    5) Select the workbook to copy to using the drop down To book:
    6) Select where you want the copied sheet to be placed by selecting a sheet in the Before sheet: list.
    7) Check the box labeled Create a copy.

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    09-17-2008
    Location
    UK
    Posts
    3

    copy entire worksheet to current workbook using VBA

    Hi,

    Thanks, but this is not a one time event. I would like to automate the process using VBA. I already have code to edit, and format the results but I am struggling with a clean simple way to import the worksheet.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello AJHWilliams,

    This macro will let you select the workbook from the directory you choose. The worksheet you specify in the macro will copied to the workbook running the macro. The chosen workbook will be closed when the worksheet is copied or an error is encountered. You specify both the worksheet name you want to copy and the new name it will be given. The names are marked in red.
    Please Login or Register  to view this content.
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    09-17-2008
    Location
    UK
    Posts
    3
    Hi Leith,

    I have tried this and it works as described - many thanks! The only line it fails on is Application.ScreeenUpdating = True , I have edited this out for the moment.

    Regards - Andrew.

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    AJHWilliams,

    Leith had one to many e's

    Try

    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  7. #7
    Registered User
    Join Date
    09-16-2011
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: copy entire worksheet to current workbook

    Hello there - hopefully the original author of this is still around. I'm having some trouble debugging your script using Excel 2011.
    I am getting the error message: "'GetOpenFilename' of object '_Application' failed"

    Is there any chance you are able to help? I'm not sure what went wrong. I resaved from .xlsx to .xls to mitigate any update-related extension issues but I'm not sure where else to go from there, as this macro is way over my head.

    Ben

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: copy entire worksheet to current workbook

    The problem is that the filter on the GetOpenFileName is for Windows.
    Windows has established a different filter structure for Mac Excel. And their implementation doesn't work very well.

    The workaround is to use the MacScript command to access AppleScript.

    This conditionaly formatted code will work on both platforms.
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Add multiple spreadsheets to single spreadsheet
    By tmotommyo in forum Excel General
    Replies: 5
    Last Post: 02-06-2008, 11:35 PM
  2. Writing cells on a protected worksheet in a shared workbook
    By Weebie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-18-2007, 08:16 PM
  3. using cell content to reference a worksheet tab name in second workbook
    By Conor in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-29-2007, 09:32 AM
  4. Copy from 1st workbook and paste to 2nd workbook
    By cheelie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-11-2007, 01:24 PM
  5. Worksheet copy problem
    By Willow in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2006, 09:56 AM

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