在EXCEL中怎么导入VB,在VB中EXCEL怎么应用
答案:3 悬赏:0
解决时间 2021-02-28 03:16
- 提问者网友:恋你成殇
- 2021-02-27 14:37
在EXCEL中怎么导入VB,在VB中EXCEL怎么应用
最佳答案
- 二级知识专家网友:修女的自白
- 2021-02-27 15:06
Private Sub Form_Load()
Set XlApp = CreateObject("Excel.Application")
XlApp.Workbooks.Open App.Path & "\123.xls" '文件位置
For i = 1 To XlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count ' 从第一行到尾行
List1.AddItem XlApp.Workbooks(1).Worksheets(1).Cells(i, 1).Text
Next
XlApp.Quit
End Sub
Set XlApp = CreateObject("Excel.Application")
XlApp.Workbooks.Open App.Path & "\123.xls" '文件位置
For i = 1 To XlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count ' 从第一行到尾行
List1.AddItem XlApp.Workbooks(1).Worksheets(1).Cells(i, 1).Text
Next
XlApp.Quit
End Sub
全部回答
- 1楼网友:眠于流年
- 2021-02-27 17:01
excel中的工具——宏——vb编辑器,就可以应用vb
vb中要引用excel,然后在应用excel
- 2楼网友:一场云烟
- 2021-02-27 16:42
首先需要引用excel库: 从"工程"菜单中选择"引用"栏;选择microsoft excel 11.0 object library(excel2003),然后选择"确定"。表示在工程中要引用excel类型库。 private sub command1_click() dim excelapp as excel.application set excelapp = createobject("excel.application") excelapp.workbooks.open (app.path & "\test2.xls") with msflexgrid1 .rows = excelapp.sheets(1).usedrange.rows.count .cols = 4 for r = 0 to .rows - 1 for c = 1 to .cols if c = 1 then .textmatrix(r, c - 1) = year(date) & "-" & excelapp.sheets(1).cells(r + 1, c + 1) & "-" & excelapp.sheets(1).cells(r + 1, c) else .textmatrix(r, c - 1) = excelapp.sheets(1).cells(r + 1, c + 1) end if next next end with excelapp.quit end sub private sub command2_click() open app.path & "\导出.txt" for output as #1 with msflexgrid1 for r = 0 to .rows - 1 for c = 0 to .cols - 1 print #1, .textmatrix(r, c); if c < .cols - 1 then print #1, ","; next print #1, next end with close #1 msgbox "导出完毕" end sub 至于滚动条,是要数据超过容器大小后才会显示出来
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯