View Single Post
 
Old 02-09-2012, 04:08 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi tinfanide,

It's because your 'Cells' references don't point to the 'sheet'.

BTW, it's not good practice to use names like 'sheet', as you can very quickly get that messed up with '.Sheet'. Furthermore, I see you're still trying to select things. You rarely need to select anything. For example:
Code:
Sub Test()
Dim xlWkBk As Workbook
Dim xlSht As Worksheet
Set xlWkBk = Workbooks("test.xls")
Set xlSht = xlWkBk.Worksheets("Sheet1")
With xlSht
  'do something, eg define a range to work on:
  With .Range(.Cells(23, 2), .Cells(47, 2))
    'do something, eg populate the defined range:
    .Value = Now
  End With
End With
Set xlSht = Nothing: Set xlWkBk = Nothing
End Sub
PS: Your question concerns Excel vba, but you posted it in the Word vba forum. I've moved it to the Excel forum.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote