PDA

View Full Version : run time error 1004



oleg_v
09-19-2010, 03:06 AM
hi
i have this code:
Sub Read_tex_File()
Dim I As Integer
Dim K As Long
Dim File1 As Long
Dim File2 As Long
Dim filename1 As String
Dim filename2 As String
Dim stext As String
Dim stex2 As String
On Error GoTo Err_Report
I = 0
File1 = FreeFile
filename1 = "C:\Documents and Settings\oleg_volfson\Desktop\test.txt" '"C:\Documents and Settings\oleg_volfson\Desktop\results.TXT
Open filename1 For Input As File1
File2 = FreeFile
filename2 = "C:\Documents and Settings\oleg_volfson\Desktop\test2.txt" '"C:\Documents and Settings\oleg_volfson\Desktop\results2.TXT
Open filename2 For Output As File2
K = 1
Do While Not EOF(File1)
K = K + 1
ThisWorkbook.Worksheets(2).Select
Input #File1, stext
If ((K Mod 2) = 0) Then 'this line cheks if the number is Even or Odd
Cells(2, 1).Select
Cells(2, 1) = stext
Else
Err.Clear
ThisWorkbook.Worksheets(2).Select
Cells(3, 1).Select
Cells(3, 1) = stext
End If
Err_Report:
'MsgBox Err.Description & " - " & Err.Number
Err.Clear
If Cells(2, 1).Value = Cells(3, 1).Value Then
GoTo ru
End If
If (Len(stext) = 80 And Left(Right(stext, 7), 4) = "Page") _
Or (Right(stext, 5) = "ERROR") Or stext = "============================================" Or _stext = " --------------------------------------------------------------------------------" Or Len(stext) = 0 Then
Else
Print #File2, stext
End If
'If stext = "--------------------------------------------------------------------------------" Then
' I = I + 1
'Print #File2, "dim" & I
'End If
ru:
Loop
Close File1
Close File2
Kill filename1
Name filename2 As filename1
End Sub

after a while that the macro runs pefactly
i have a 'object difined error 1004'
in this line
" Cells(3, 1) = stext"
please help me to over come this problem

thanks

Bob Phillips
09-19-2010, 10:03 AM
Maybe



Do While Not EOF(File1)
K = K + 1

ThisWorkbook.Worksheets(2).Select
Input #File1, stext
If Not EOF(File1) Then

If ((K Mod 2) = 0) Then 'this line cheks if the number is Even or Odd
Cells(2, 1).Select
Cells(2, 1) = stext
Else
Err.Clear
ThisWorkbook.Worksheets(2).Select
Cells(3, 1).Select
Cells(3, 1) = stext
End If

Err_Report:
'MsgBox Err.Description & " - " & Err.Number
Err.Clear

If Cells(2, 1).Value = Cells(3, 1).Value Then
GoTo ru
End If

If (Len(stext) = 80 And Left(Right(stext, 7), 4) = "Page") Or _
(Right(stext, 5) = "ERROR") Or _
stext = "=========================================================================== =====" Or _
stext = " --------------------------------------------------------------------------------" Or _
Len(stext) = 0 Then

Else
Print #File2, stext
End If

'If stext = "--------------------------------------------------------------------------------" Then
' I = I + 1
'Print #File2, "dim" & I

'End If
End If
ru:
Loop