试试 Private Sub Command1_Click() Dim strTmp As String Open "C:\1.csv" For Input As #1 While EOF(1) = False Line Input #1, strTmp If Trim(strTmp) <> "" Then MsgBox "有数据" Exit Sub End If Wend End Sub
Dim s$ Open "x:\temp\Test.csv" For Input As #1 Do While (Not EOF(1)) Input #1, s If (Len(Replace$(Replace$(s, " ", ""), ",", "")) > 0) Then MsgBox "文件包含有效数据!", 64, "消息" Exit Do End If Loop Close
文件大小为0是肯定没数据的.
所以,这样判断太单纯了,如果要判断CSV文件里至少有一行有效数据,该如何判断?
谢谢。
Private Sub Command1_Click()
Dim strTmp As String
Open "C:\1.csv" For Input As #1
While EOF(1) = False
Line Input #1, strTmp
If Trim(strTmp) <> "" Then
MsgBox "有数据"
Exit Sub
End If
Wend
End Sub
Open "x:\temp\Test.csv" For Input As #1
Do While (Not EOF(1))
Input #1, s
If (Len(Replace$(Replace$(s, " ", ""), ",", "")) > 0) Then
MsgBox "文件包含有效数据!", 64, "消息"
Exit Do
End If
Loop
Close