How can I include a workbook name when specifying a Range in VBA code?

K

keithb

How can I include a workbook name when specifying a Range in VBA code?

Thanks,

Keith
 
N

Norman Jones

Hi Heith,

One way:

Sub Tester08()
Dim WB As Workbook
Dim WS As Worksheet
Dim Rng As Range


Set WB = Workbooks("MyWorkBook")
Set WS = WB.Sheets("MysheetName")
Set Rng = WS.Range("A1:D100")

End Sub
 
N

Norman Jones

Hi Keith,

Just to add, if the workbook has previously been saved, then you must
include the extension (e.g.: .xls) in the workbook name.

So:
Set WB = Workbooks("MyWorkBook")

should be in the form:

Set WB = Workbooks("MyWorkBook.xls")

for a saved workbook.
 
Top