View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
L.Mathe L.Mathe is offline
external usenet poster
 
Posts: 24
Default Error 1004-application or object error

Using Excel 2003. I'm trying to use VBA to select & open a csv file, search
for specific text (using the data in Cell A1 of my wb), etc. However, I am
getting a Run-Time error 1004. Where am I going wrong? The code in part is
as follows:

Sub GetFile()

Dim FileName As Variant
FileName = Application.GetOpenFilename
If FileName = False Then
Debug.Print "user cancelled"
Else
Debug.Print "file selected: " & FileName
End If

Call ReadCSV2(myFileName, SearchData, DestSht)

End Sub


Sub ReadCSV2(ByVal myFileName, ByVal SearchData As String, ByVal DestSht)

DestSht = "sheet1"
With ThisWorkbook.Sheets(DestSht)
SearchData = .Range("A1").Text
End With

Dim Data As String
Dim Data1 As Date
Dim Data2 As String
Dim Data3 As String

LastRow = ThisWorkbook.Sheets(DestSht) _
..Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow + 1
RowCount = NewRow
FName = "Temp"
Do While FName < ""

Workbooks.OpenText FileName:="Temp", DataType:=xlDelimited, Comma:=True
Set CSVFile = ActiveWorkbook
Set CSVSht = CSVFile.Sheets(1)
'check if data exists in column 77
Set c = CSVSht.Columns(77).Find(What:=SearchData, _
LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
FirstAddr = c.Address ,,,,,,etc


I get the error code when it hits the line:
Workbooks.OpenText FileName:="Temp", DataType:=xlDelimited, Comma:=True

Can someone please help, I'm getting frustrated!
Thanks
--
Linda