乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>vb</em>6.0如何<em>读取excel</em>工作表的

<em>vb</em>6.0如何<em>读取excel</em>工作表的

作者:乔山办公网日期:

返回目录:excel表格制作


Dim SheetID As Integer
Dim XlsRow As Long
Dim TotalBit As Integer
Dim MachineID00_Msg000(i) As String
Dim i As Integer
SheetID = 3 设定表编号,即Sheet的编号。
Set ExcelApp = CreateObject("Excel.Application") '
Set ExcelBook = ExcelApp.Workbooks.Open(App.Path + "\Pameter.dat") '路径
Set ExcelSheet = ExcelBook.Worksheets(SheetID) '
XlsRow = 2 '读取起始行
TotalBit = 16 '要读取的行数
For i = 0 To (TotalBit - 1)
MachineID00_Msg000(i) = ExcelSheet.Range("D" & XlsRow).value
XlsRow = XlsRow + 1 '循还e79fa5e98193e59b9ee7ad94364
Next i
ExcelApp.quit
Set ExcelSheet = Nothing
Set ExcelBook = Nothing
Set ExcelApp = Nothing

strSQl = "select * from [" & strSheetName & "]" 取掉“&”字符
用CommonDialog可以解决选定打开.xls文件问e5a48de588b67a64331题 然后就是读取进去 哈哈 保存代码如下

'添加command控件一个 MSFlexGrid控件一个
Private Sub Command1_Click()
On Error Resume Next
Dim fileadd As String
CommonDialog1.ShowOpen
CommonDialog1.Filter = "xls文件(*.xls)|*.xls" '选择你要的文件
fileadd = CommonDialog1.FileName
MSHFlexGrid1.Redraw = False '关闭表格重画,加快运行速度
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Open(fileadd) '打开已经存在的EXCEL工件簿文件
xlApp.Visible = True '设置EXCEL对象可见(或不可见)
Set xlsheet = xlBook.Worksheets("Sheet1") '设置活动工作表

For R = 0 To MSHFlexGrid1.Rows - 1 '行循环
For C = 0 To MSHFlexGrid1.Cols - 1 '列循环
MSHFlexGrid1.Row = R
MSHFlexGrid1.Col = C
xlBook.Worksheets("Sheet1").Cells(R + 1, C + 1) = MSHFlexGrid1.Text '保存到EXCEL
Next C
Next R

MSHFlexGrid1.Redraw = True

xlApp.DisplayAlerts = False '不进行安全提示
'Set xlsheet = Nothing
'Set xlBook = Nothing
'xlApp.Quit
'Set xlApp = Nothing
End Sub

下面的例子,供你参考:

’用CommonDialog可以解决选定打开.xls文件问题 然后就是读取进去 哈哈 保存代码如下 

'添加command控件一个 CommonDialog,MSFlexGrid控件一个 
Private Sub Command1_Click() 
On Error Resume Next 
Dim fileadd As String 
CommonDialog1.ShowOpen 
CommonDialog1.Filter = "xls文件(*.xls)|e79fa5e98193e4b893e5b19e335*.xls" '选择你要的文件 
fileadd = CommonDialog1.FileName 
MSHFlexGrid1.Redraw = False '关闭表格重画,加快运行速度 
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象 
Set xlBook = xlApp.Workbooks.Open(fileadd) '打开已经存在的EXCEL工件簿文件 
xlApp.Visible = True '设置EXCEL对象可见(或不可见) 
Set xlsheet = xlBook.Worksheets("Sheet1") '设置活动工作表 

For R = 0 To MSHFlexGrid1.Rows - 1 '行循环 
For C = 0 To MSHFlexGrid1.Cols - 1 '列循环 
MSHFlexGrid1.Row = R 
MSHFlexGrid1.Col = C 
‘这里写你 SQL语句
Next C 
Next R 

MSHFlexGrid1.Redraw = True 

xlApp.DisplayAlerts = False 
'Set xlsheet = Nothing 
'Set xlBook = Nothing 
'xlApp.Quit 
'Set xlApp = Nothing 
End Sub

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网