VB 如何获得Excel的工作表数和名称?
本人在VB程序中要打开一个Excle(数据),打开后如何获得其中工作表数和名称。我用以下程序不行,请高手指正。谢谢!gzb.ConnectionString="Provi...
本人在VB程序中要打开一个Excle(数据),打开后如何获得其中工作表数和名称。
我用以下程序不行,请高手指正。谢谢!
gzb.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source=数据.xls;Extended Properties='Excel 8.0;HDR=Yes'"
gzb.Open
Dim i As Integer
dim zd as integer
Dim gzbm(10) As String
zd = gzb.Worksheets.Count(此处出错,要求对象)
For i= 1 To zd
gzbm(i) = gzb(i).Name
Next i 展开
我用以下程序不行,请高手指正。谢谢!
gzb.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source=数据.xls;Extended Properties='Excel 8.0;HDR=Yes'"
gzb.Open
Dim i As Integer
dim zd as integer
Dim gzbm(10) As String
zd = gzb.Worksheets.Count(此处出错,要求对象)
For i= 1 To zd
gzbm(i) = gzb(i).Name
Next i 展开
3个回答
展开全部
是挺乱的。。
或者是
cells(x1,y1)
ts
then
ii
=
i
elseif
xlapp.cells(i,
2).value
=
ts
then
ii
=
i
这为什么不写成
elseif
xlapp.cells(i,
2).value
>
=ts
then
ii
=
i
你是只要查找b列=ts的行号吗?
dim
srt
as
string
dim
i
as
integer
srt
="等于ts的行号有"
for
i
=
1
to
65536
if
xlapp.cells(i,
2).value
=
ts
then
srt=
srt
&
","
&
i
end
if
next
i
msgbox
srt
没跑过。。不知道行不行。。
或者是
cells(x1,y1)
ts
then
ii
=
i
elseif
xlapp.cells(i,
2).value
=
ts
then
ii
=
i
这为什么不写成
elseif
xlapp.cells(i,
2).value
>
=ts
then
ii
=
i
你是只要查找b列=ts的行号吗?
dim
srt
as
string
dim
i
as
integer
srt
="等于ts的行号有"
for
i
=
1
to
65536
if
xlapp.cells(i,
2).value
=
ts
then
srt=
srt
&
","
&
i
end
if
next
i
msgbox
srt
没跑过。。不知道行不行。。
展开全部
这样应该可以的。
估计是楼主你没有引用Excel的对象库:
project -> References -> Microsoft Excel xx.0 Object Library
Office 97:
Microsoft Excel 8.0 Object Library
Office 2000:
Microsoft Excel 9.0 Object Library
Office XP:
Microsoft Excel 10.0 Object Library
Office 2003:
Microsoft Excel 11.0 Object Library
估计是楼主你没有引用Excel的对象库:
project -> References -> Microsoft Excel xx.0 Object Library
Office 97:
Microsoft Excel 8.0 Object Library
Office 2000:
Microsoft Excel 9.0 Object Library
Office XP:
Microsoft Excel 10.0 Object Library
Office 2003:
Microsoft Excel 11.0 Object Library
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
首先你要引用excel对象库,工程 - 引用 - Microsoft Excel 11.0 Object Library
sub getxls()
Dim xapp As New Excel.Application
Dim wb As Workbook
Dim ws As Worksheet
Dim gzbm() As String
Set wb = xapp.Workbooks.Open(app.path & "/数据.xls")
zd = wb.Worksheets.Count
ReDim gzbm(zd - 1)
debug.print zd
For Each ws In wb.Sheets
gzbm(i) = ws.Name
i = i + 1
Debug.Print ws.Name
Next
xapp.Quit
Set ws = Nothing
Set wb = Nothing
Set xpp = Nothing
end sub
子易空间站 - Excel培训专家
sub getxls()
Dim xapp As New Excel.Application
Dim wb As Workbook
Dim ws As Worksheet
Dim gzbm() As String
Set wb = xapp.Workbooks.Open(app.path & "/数据.xls")
zd = wb.Worksheets.Count
ReDim gzbm(zd - 1)
debug.print zd
For Each ws In wb.Sheets
gzbm(i) = ws.Name
i = i + 1
Debug.Print ws.Name
Next
xapp.Quit
Set ws = Nothing
Set wb = Nothing
Set xpp = Nothing
end sub
子易空间站 - Excel培训专家
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询