PDA

View Full Version : Solved: Need help with copying data from another workbook



doctortt
05-06-2011, 09:45 AM
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?

JP2112
05-06-2011, 12:46 PM
GetOpenFilename only returns the filename. You'll need to open the workbook, then copy the sheet. Something like this:


Dim myWorkbook As Excel.Workbook
Set myWorkbook = Workbooks.Open(OpenFile)
myWorkbook.Sheets("Data").Copy After:=ActiveWorkbook.Sheets(1)

doctortt
05-06-2011, 01:01 PM
thank you, it works.