Select method failing

C

CDM

I'm trying to remove a header row in a different spreadsheet with the
following code. Everything goes OK until it gets to .Range("A1").select. It
gives me an error message that says, "Select method of Range class failed."
What am I missing?

Dim objWkBook As Object
Dim objWkSheet As Object

Set objWkBook = GetObject("Z:\AgingByLocation.xls")
Set objWkSheet = objWkBook.Worksheets(1)
With objWkSheet
.Activate
.Rows(1).Delete Shift:=xlUp
.Range("A1").Select
End With
 
J

Jacob Skaria

You are trying to activate a cell which is not opened...If you are looking to
select a range then try the below code which opens the workbook..

Dim objWkBook As Workbook
Dim objWkSheet As Worksheet

Set objWkBook = Workbooks.Open("c:\3.xls")
Set objWkSheet = objWkBook.Worksheets(1)
With objWkSheet
.Activate
.Rows(1).Delete Shift:=xlUp
.Range("A1").Activate
End With
objWkBook.Close
 

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

Top