VB如何获取excel工作表的名字
vb.net吧
全部回复
仅看楼主
level 7
暴牙归来 楼主
2016年06月26日 12点06分 1
level 7
暴牙归来 楼主
2016年06月26日 12点06分 2
level 7
暴牙归来 楼主
@闪星2 我根据你的代码做了相关修改,但结果是这样的
修改后的代码:
Try
Dim cat As Object
Dim cn As Object
Dim tbl As Object
Dim xlssql As String
cn = CreateObject("provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & Me.ListBox1.SelectedItems(n))
cat = CreateObject(Me.ListBox1.SelectedItems(n))
Debug.Print("filename=" & Me.ListBox1.SelectedItems(n))
If InStr(Me.ListBox1.SelectedItems(n), "xlsx") > 0 Then
cn.Open("Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & Me.ListBox1.SelectedItems(n) & ";Extended Properties='Excel 12.0 Xml;HDR=Yes;IMEX=1'")
Else
cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Me.ListBox1.SelectedItems(n) & ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'")
End If
cat.ActiveConnection = cn
For Each tbl In cat.Tables
Debug.Print(tbl.Name)
If InStr(tbl.Name, "$") > 0 Then
Me.ListBox2.Items.Add(tbl.Name)
End If
Next
tbl = Nothing
cat = Nothing
cn = Nothing
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "工作表读取失败")
End Try
其中的Me.ListBox1.SelectedItems(n)是指下面这个
2016年06月27日 07点06分 6
顺便问一下ActiveX组件在哪里下载比较放心@闪星2
2016年06月27日 07点06分
1