I want to read data from excel file and write the data to a table. I cant use excel.application because microsoft office is not installed.
Public Function ImportExcel(CommonDialog1 As Object)
Dim sFilePath As String
Dim fso As New FileSystemObject
Dim txtStream As TextStream
Dim sRowRange As Range
Dim nRows As Integer
Dim str As String
'Set the settings for the Common dialogue box and Show
Set CommonDialog1 = CreateObject("MSComDlg.CommonDialog.1")
CommonDialog1.Filter = "Microsoft Excel Workbook(*.xls)"
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
sFilePath = CommonDialog1.FileName
If UCase(Right(Trim(sFilePath), 3)) = "XLW" Or UCase(Right(Trim(sFilePath), 3)) = "XLS" Or UCase(Right(Trim(sFilePath), 4)) = "XLSX" Or UCase(Right(Trim(sFilePath), 3)) = "CSV" Then
Set fso = New FileSystemObject
Set txtStream = fso.OpenTextFile(sFilePath, ForReading, False)
Do While Not txtStream.AtEndOfStream
str = txtStream.ReadLine
Loop
txtStream.Close
Else
MsgBox "Make sure your selected file has file extension xlw or xls", vbOKOnly + vbInformation
Exit Function
End If
End If
End Function