Consulting

Results 1 to 3 of 3

Thread: Solved: Need help with copying data from another workbook

  1. #1

    Solved: Need help with copying data from another workbook

    I'm a newb, struggling with copying data from another workbook. Can someone help me out

    OpenFile = Application.GetOpenFilename(FileFilter:="Excel files(*.xls), *.xls")

    This code will bring up the open file prompt and after the user select the .xls file, how do I copy all data on a worksheet called Data to the active workbook that i'm working on?

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    GetOpenFilename only returns the filename. You'll need to open the workbook, then copy the sheet. Something like this:

    [VBA]
    Dim myWorkbook As Excel.Workbook
    Set myWorkbook = Workbooks.Open(OpenFile)
    myWorkbook.Sheets("Data").Copy After:=ActiveWorkbook.Sheets(1)
    [/VBA]
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  3. #3
    thank you, it works.

Posting Permissions

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