ianverrier
New member
- Local time
- Today, 02:17
- Joined
- Dec 20, 2010
- Messages
- 3
I wrote the following code in visual basic to copy column C to column IH in an excel worksheet but I get this error when trying to select column C:
Run-time error '1004':
Select method of Range class failed
Sub TestExceladfd(current_path, rnc As String) 'subroutine copies the utancell field in the utrancell worksheet to field IH
Dim objXL As Object
Dim xlWB As Object
Dim xlWS As Object
Dim strPathAndFileName As String
Const xlToLeft As Long = -4159
Set objXL = CreateObject("Excel.Application")
objXL.Visible = True
strPathAndFileName = current_path & "\input_files\" & rnc & ".xls"
Set xlWB = objXL.Workbooks.Open(strPathAndFileName)
Set xlWS = xlWB.Worksheets("UtranCell")
xlWS.Columns("C").Select '*** fails here
objXL.Selection.Copy
xlWS.Columns("IH").Select
objXL.ActiveSheet.Paste
xlWB.Save
xlWB.Close
objXL.Quit
Set objXL = Nothing
End Sub
Strange thing is I believe this same code worked before.
Any ideas?
Ian
Run-time error '1004':
Select method of Range class failed
Sub TestExceladfd(current_path, rnc As String) 'subroutine copies the utancell field in the utrancell worksheet to field IH
Dim objXL As Object
Dim xlWB As Object
Dim xlWS As Object
Dim strPathAndFileName As String
Const xlToLeft As Long = -4159
Set objXL = CreateObject("Excel.Application")
objXL.Visible = True
strPathAndFileName = current_path & "\input_files\" & rnc & ".xls"
Set xlWB = objXL.Workbooks.Open(strPathAndFileName)
Set xlWS = xlWB.Worksheets("UtranCell")
xlWS.Columns("C").Select '*** fails here
objXL.Selection.Copy
xlWS.Columns("IH").Select
objXL.ActiveSheet.Paste
xlWB.Save
xlWB.Close
objXL.Quit
Set objXL = Nothing
End Sub
Strange thing is I believe this same code worked before.
Any ideas?
Ian