opening a workbook with VBA

  • Thread starter Thread starter wagee
  • Start date Start date
Workbooks.Open("path to your workbook\name of your workbook.xls")
 
Sorry the brackets are not required as it's being used as a procedure
not a function.

Workbooks.Open "path to your workbook\name of your workbook.xls"

Cheers,
Jason Lepack
 
Sorry the brackets are not required as it's being used as a procedure
not a function.

Workbooks.Open "path to your workbook\name of your workbook.xls"

Cheers,
Jason Lepack





- Show quoted text -

Thanks very much Jason! You have proved my thickness. I was using
brackets instead of quotes.....another day wasted<sigh> Thanks again.
Wayne
 
Now, if you were intending to do more with that worksheet then these
are some common variables that I use:

option explicit
public sub do_stuff_with_wb()
dim wb as workbook
dim ws as Worksheet
dim r as range

set wb = Workbooks.open("wb_path\wb_name.xls")
set ws = wb.activesheet ' uses the active sheet of the workbook just
opened
set ws = wb.sheets(2) ' uses the second sheet of the workbook

set ws = wb.sheets.add
ws.name = "your_sheet"

set r = ws.range("A1") ' r points to cell A1 of your_sheet
set r = ws.offset(2,2) ' moves two rows down and two colums right
(C3)
set r = ws.offset(-1,-1) ' moves one row up and one column left (B2)

r.value = "Hi!" ' sets the value of B2 to "Hi!"

set r = nothing
set ws = nothing
set wb = nothing
end sub

Cheers,
Jason Lepack
 

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