Open excel workbook within macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi! I have a macro that opens a file and goes through a list. If ceratian
things are found in the list I want to open an Excel file and read from that
file to the original file. How do I open an excel file from a macro and how
can I read from it? Thanks!
 
This is right out of VBA help file.

Sub OpenUp()
Workbooks.Open("C:\MyFolder\MyBook.xls")
End Sub

If the file you want to open is in the same directory as the active
workbook, then you don't need the full path. Once open, you can access it
and manipulate data much the same as the active sheet, but you will need to
use the workbook and sheet references as you do it like.

Workbooks("MyBook"),Sheets(1).Range("A1:B5").Copy
Workbooks(ActiveWorkbook).Sheets(1).Range("A1")

Good Luck.
 
Sub Macro1()
Workbooks.Open Filename:="C:\surprise.xls"
MsgBox (Range("A1").Value)
End Sub
 
Hi Arne

i hope the code below clears things up for you a bit

'open your workbook giving the full location and name
Workbooks.Open ("C:\test\filename.xls")
'activate the workbook you want to work with
Workbooks("filename.xls").Activate
[A1:A20].Copy 'for example
'activate the original workbook and paste
Workbooks("original.xls").Activate
[A1].PasteSpecial (xlPasteAll)

hope this helps

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top