标题:VB 读excel 数据(用commondialog)
取消只看楼主
jluzhangchen
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-7-11
 问题点数:0 回复次数:1 
VB 读excel 数据(用commondialog)
这个是我写的 我也引用部件了,excel也引入了
但是只能显示对话框
不能显示msgbox 我想可能是没有进行excel读入操作
请高手看看哪里的问题
Dim bb(1000,1000) as Double
Private Sub Command1_Click()
Me.AutoRedraw = True
Dim xlsApp As Excel.Application
Dim xlsworkbook As Excel.Workbook
Dim xlssheet As Excel.Worksheet
Dim sFile As String


On Error GoTo ErrHandler
CommonDialog1.Filter = "ALL Files(*.*)|*.*|" & "Text Files(*.xls)|*.xls|"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then
Exit Sub
End If
sFile = CommonDialog1.FileName

Set xlsApp = CreateObject("Excel.Application")

Set xlsworkbook = xlsApp.Workbooks.Open(sFile)


xlsApp.Visible = True

Set xlssheet = xlsworkbook.Worksheets("Sheet1")
xlssheet.Activate

Dim i, j As Integer
For i = 0 To xlssheet.UsedRange.Rows.Count - 1
  For j = 0 To xlssheet.UsedRange.Columns.Count - 1
     b(i, j) = xlssheet.Cells(i, j)
    Next j
Next i

Set xlssheet = Nothing
Set xlsworkbook = Nothing
Set xlsApp = Nothing

MsgBox "数据导入完毕!"
ErrHandler:
 Exit Sub
End Sub
搜索更多相关主题的帖子: excel commondialog 数据 
2010-05-15 22:08
jluzhangchen
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-7-11
得分:0 
谢谢!!
数据变量哪里有问题?
是b么??
我就是把b设定的大一点
2010-05-17 21:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-306805-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.286484 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved