|
将以下函数稍作更改就可以了:
'===============================================================================
'-函数名称: GetExcelSheel
'-功能描述: 获取文件信息Excel文件的工作表名称
'-输入参数说明: 参数1: 必选 strExcelFile As String Excel文件路径和名称
'-返回参数说明: 返回Excel文件的工作表名称
'-使用语法示例: Msgbox GetExcelSheel("C:\Abc.xls")
'-参考:
'-使用注意: 需要引用ADOX
'-兼容性: 2000,XP,2003
'-作者: fan0217@tom.com
'-更新日期: 2006-05-20
'===============================================================================
Function GetExcelSheel(strExcelFile As String) As String
On Error GoTo Err_GetExcelSheel
Dim cat As New ADOX.Catalog
Dim strTemp As String
Dim i As Integer
cat.ActiveConnection = "Driver=Microsoft Excel Driver (*.xls);dbq=" & strExcelFile
For i = 0 To cat.Tables.Count - 1
strTemp = strTemp & Left(cat.Tables(i).Name, Len(cat.Tables(i).Name) - 1) & ";"
'strTemp = strTemp & cat.Tables(i).Name & ";"
Next
GetExcelSheel = Left(strTemp, Len(strTemp) - 1)
Set cat = Nothing
Exit_GetExcelSheel:
Exit Function
Err_GetExcelSheel:
Set cat = Nothing
MsgBox Err.Description
Resume Exit_GetExcelSheel
End Function
|
|