下面的例子,供你参考:
’用CommonDialog可以解决选定打开.xls文件问题 然后就是读取进去 哈哈 保存代码如下
'添加command控件一个 CommonDialog,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
‘这里写你 SQL语句
Next C
Next R
MSHFlexGrid1.Redraw = True
xlApp.DisplayAlerts = False
'Set xlsheet = Nothing
'Set xlBook = Nothing
'xlApp.Quit
'Set xlApp = Nothing
End Sub
用VSTO吧,不要再用VB6.0了,或者直接用Excel里面自带的VBA来操作,写入到SQL.