|
-
May 22nd, 2006, 09:22 AM
#1
Thread Starter
Junior Member
[RESOLVED] First thread in this site, problem with reading from excel,help~
Firstly I have to tell u that I am a Chinese boy, so maybe I will not quite understand what u experts have responded and ask again for solution, sorry for that.
Well, to the problem. I am trying to read from an Excel file including 2 cols and unsure rows, and I wanna get all these rows to be written into my access file. Firstly, I have to ensure that none of these rows can be null. I wrote these codes, yet the problem shows now:
1. Only when I open the file manually can the file be accessed by my application. (The excel file is in MyDocument folder, can it be the problem of permission that refused me???)
2. I found quite a lot of copies of application "Excel.exe" running in my processes explorer.(This happens when I tested for quite a time). I cannot quit this application????
VB Code:
Public Function ValidateExcelFile(strFilePath As String) As Boolean
Set appExcel = New Excel.Application
Set wbExcel = appExcel.Workbooks.Open(strFilePath)
Set wsExcel = wbExcel.Sheets(1)
Dim lRowNum As Long
Dim lColNum As Long
lColNum = wsExcel.UsedRange.Columns.Count
lRowNum = wsExcel.UsedRange.Rows.Count
If lColNum <> 2 Then
ValidateExcelFile = False
appExcel.Quit
Set appExcel = Nothing
Set wbExcel = Nothing
Set wsExcel = Nothing
'Exit Function
Else
Dim i
For i = 2 To lRowNum
If wsExcel.Cells(i, 1).Value = "" Then
ValidateExcelFile = False
Err.Raise "100", , modWizard.GetResString("3004")
appExcel.Quit
Set appExcel = Nothing
Set wbExcel = Nothing
Set wsExcel = Nothing
Exit Function
End If
Next
ValidateExcelFile = True
appExcel.Quit
Set appExcel = Nothing
Set wbExcel = Nothing
Set wsExcel = Nothing
End If
End Function
Hope you guys can help me~~~A help from China )
Thanks.
Last edited by si_the_geek; May 22nd, 2006 at 09:39 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|