I think Bob meant
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets(1)
Msgbox ws.Range("A1").Value
--
Regards,
Tom Ogilvy
"Bob Phillips" wrote in message
...
Andi,
I have looked at teh article, and I cannot see anything remotely like what
you have posted.
To your question.
Dim ws As Worksheet
ws = ThisWorkbook.Worksheets(1)
Msgbox ws.Range("A1").Value
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Andibevan" wrote in
message
...
I have been reading the following item:-
http://msdn.microsoft.com/library/de...heetranges.asp
and it uses the following code:-
Dim ws As Excel.Worksheet = _
DirectCast(ThisWorkbook.Worksheets(1), Excel.Worksheet)
Dim rng, rng1, rng2 As Excel.Range
but when I try and use it, the first two lines show up in red in the VBA
editor.
Is there a reason for this? I am using Excel 2000, is there an add-in or
something I need to use the "DirectCast"?
Basically I am after a few pointers on how to refer to worksheet ranges
from
code but am getting stuck.
Thanks
Andi