newdev
Nov 12th, 2002, 10:07 AM
Trying to put the text file data into Excel.
Sub ImportRange()
Dim impRng As Range
Dim fileName As String
Dim r As Long
Dim c As Integer
Dim txt As String
Dim char1 As String
Dim data
Dim i As Integer
Dim objXL As New Excel.Application()
Dim wbXL As New Excel.WorkbookClass()
Dim wsXL As New Excel.Worksheet()
impRng = objXL.ActiveCell
On Error Resume Next
fileName = "C:\Test.txt"
r = 0
c = 0
txt = " "
objXL.Visible = True
wbXL = objXL.Workbooks.Add
wsXL = CType(objXL.ActiveSheet, Excel.Worksheet)
' name the worksheet
FileOpen(1, fileName, OpenMode.Input)
objXL.ScreenUpdating = False
Do Until EOF(1)
data = LineInput(1)
For i = 1 To Len(data)
char1 = Mid(data, i, 1)
If char1 = "," Then
wsXL.Cells(r, c) = txt
c = c + 1
txt = " "
ElseIf i = Len(data) Then
If char1 <> Chr(34) Then
txt = txt & char1
wsXL.Cells(r, c) = txt
txt = " "
ElseIf char1 <> Chr(34) Then
txt = txt & char1
End If
End If
Next
c = 0
r = r + 1
Loop
objXL.ScreenUpdating = True
End Sub
I get the following error on Line 11.
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in WindowsApplication12.exe
Additional information: COM object with CLSID {00020819-0000-0000-C000-000000000046} is either not valid or not registered.
Please Someone help me solve this issue..
Thanx a bunch!
Sub ImportRange()
Dim impRng As Range
Dim fileName As String
Dim r As Long
Dim c As Integer
Dim txt As String
Dim char1 As String
Dim data
Dim i As Integer
Dim objXL As New Excel.Application()
Dim wbXL As New Excel.WorkbookClass()
Dim wsXL As New Excel.Worksheet()
impRng = objXL.ActiveCell
On Error Resume Next
fileName = "C:\Test.txt"
r = 0
c = 0
txt = " "
objXL.Visible = True
wbXL = objXL.Workbooks.Add
wsXL = CType(objXL.ActiveSheet, Excel.Worksheet)
' name the worksheet
FileOpen(1, fileName, OpenMode.Input)
objXL.ScreenUpdating = False
Do Until EOF(1)
data = LineInput(1)
For i = 1 To Len(data)
char1 = Mid(data, i, 1)
If char1 = "," Then
wsXL.Cells(r, c) = txt
c = c + 1
txt = " "
ElseIf i = Len(data) Then
If char1 <> Chr(34) Then
txt = txt & char1
wsXL.Cells(r, c) = txt
txt = " "
ElseIf char1 <> Chr(34) Then
txt = txt & char1
End If
End If
Next
c = 0
r = r + 1
Loop
objXL.ScreenUpdating = True
End Sub
I get the following error on Line 11.
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in WindowsApplication12.exe
Additional information: COM object with CLSID {00020819-0000-0000-C000-000000000046} is either not valid or not registered.
Please Someone help me solve this issue..
Thanx a bunch!