VB 如何生成EXCEL表格?谢谢了
用VB编了计算的小程序,结果能计算出来。现在我想把计算的中途步骤导出成word或者把中间步骤的计算结果自动生成excel中我采用了cnbubble方法怎么不行啊,出现“用...
用VB编了计算的小程序,结果能计算出来。现在我想把计算的中途步骤导出成word或者把 中间步骤的计算结果自动生成excel中
我采用了 cnbubble方法怎么不行啊,出现“用户定义类型未定义”?怎么回事啊
高手帮忙解答下,谢谢啦:-) 展开
我采用了 cnbubble方法怎么不行啊,出现“用户定义类型未定义”?怎么回事啊
高手帮忙解答下,谢谢啦:-) 展开
展开全部
Private Sub Command2_Click()
Dim objExcel As Excel.Application
Dim objWorkBook As Excel.Workbook
Set objExcel = CreateObject("Excel.Application")
Set objWorkBook = objExcel.Workbooks.Add()
objExcel.Visible = True
'设置活动工作表
Dim objSheet As Excel.Worksheet
Set objSheet = objExcel.Worksheets("sheet1")
objSheet.Cells(1, 1) = "mather" '对单元格赋值
objWorkBook.SaveAs "D:\aa.xls" '保存
objWorkBook.Close
objExcel.Quit
Set objSheet = Nothing
Set objWorkBook = Nothing
Set objExcel = Nothing
End Sub
补充: 在“工程”-引用 -中要选择 Microsoft Excel 11.0【或其他数值】 Object Library
Dim objExcel As Excel.Application
Dim objWorkBook As Excel.Workbook
Set objExcel = CreateObject("Excel.Application")
Set objWorkBook = objExcel.Workbooks.Add()
objExcel.Visible = True
'设置活动工作表
Dim objSheet As Excel.Worksheet
Set objSheet = objExcel.Worksheets("sheet1")
objSheet.Cells(1, 1) = "mather" '对单元格赋值
objWorkBook.SaveAs "D:\aa.xls" '保存
objWorkBook.Close
objExcel.Quit
Set objSheet = Nothing
Set objWorkBook = Nothing
Set objExcel = Nothing
End Sub
补充: 在“工程”-引用 -中要选择 Microsoft Excel 11.0【或其他数值】 Object Library
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我也做了这个,成功导出,你看看
dim
i,
j,
k
as
integer
dim
strcolname1
as
string
dim
strsql
as
string
dim
xlapp
as
variant
dim
xlbook
as
variant
dim
xlsheet
as
variant
'以上定义放在通用中
private
sub
label_click()
'导出execl
set
xlapp
=
createobject("excel.application")
set
xlbook
=
xlapp.workbooks.add
set
xlsheet
=
xlbook.worksheets(1)
on
error
resume
next
if
err.number
=
0
then
set
xlapp
=
createobject("excel.application")
set
xlbook
=
xlapp.workbooks.add
set
xlsheet
=
xlbook.activesheet
for
k
=
1
to
datagrid1.columns.count
xlsheet.cells(1,
k)
=
datagrid1.columns(k
-
1).caption
next
k
for
i
=
1
to
adodc1.recordset.recordcount
+
1
for
j
=
0
to
datagrid1.columns.count
xlsheet.cells(i
+
1,
j
+
1)
=
adodc1.recordset(j)
next
j
adodc1.recordset.movenext
next
i
end
if
xlapp.visible
=
true
end
sub
在窗体中放一个ado控件,并且在属性中设置与数据库的连接
dim
i,
j,
k
as
integer
dim
strcolname1
as
string
dim
strsql
as
string
dim
xlapp
as
variant
dim
xlbook
as
variant
dim
xlsheet
as
variant
'以上定义放在通用中
private
sub
label_click()
'导出execl
set
xlapp
=
createobject("excel.application")
set
xlbook
=
xlapp.workbooks.add
set
xlsheet
=
xlbook.worksheets(1)
on
error
resume
next
if
err.number
=
0
then
set
xlapp
=
createobject("excel.application")
set
xlbook
=
xlapp.workbooks.add
set
xlsheet
=
xlbook.activesheet
for
k
=
1
to
datagrid1.columns.count
xlsheet.cells(1,
k)
=
datagrid1.columns(k
-
1).caption
next
k
for
i
=
1
to
adodc1.recordset.recordcount
+
1
for
j
=
0
to
datagrid1.columns.count
xlsheet.cells(i
+
1,
j
+
1)
=
adodc1.recordset(j)
next
j
adodc1.recordset.movenext
next
i
end
if
xlapp.visible
=
true
end
sub
在窗体中放一个ado控件,并且在属性中设置与数据库的连接
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
别人问如何生成EXCEL表格,你回答生成EXE文件,牛头不对马嘴!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询