VB 如何将Combo1.Text赋值到单元格里。

PrivateSubExcle_Click()DimobjExcelAsExcel.ApplicationDimobjWorkBookAsExcel.WorkbookSe... Private Sub Excle_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) = "竖框款式"
objSheet.Cells(1, 3) = "门扇数"
objSheet.Cells(1, 5) = "色号"

objSheet.Cells(2, 1) = "门洞宽"
objSheet.Cells(3, 1) = "门洞高" '对单元格赋值
objSheet.Cells(4, 1) = "成品门总宽"
objSheet.Cells(5, 1) = "成品门总高"

objSheet.Cells(1, 2) = Str(Combo1.Text)
objSheet.Cells(1, 4) = Str(Combo2.Text)

objSheet.Cells(2, 2) = Str(Text1.Text)
objSheet.Cells(3, 2) = Str(Text2.Text)
objSheet.Cells(4, 2) = Str(Text3.Text)
objSheet.Cells(5, 2) = Str(Text4.Text)

objWorkBook.SaveAs "F:\aa.xlsx" '保存
objWorkBook.Close
objExcel.Quit
Set objSheet = Nothing
Set objWorkBook = Nothing
Set objExcel = Nothing

End Sub
执行运行后,出现,“实时错误‘13’,类型不匹配”字样。请高手指点。
展开
 我来答
ljl88900
2010-04-23 · TA获得超过2661个赞
知道大有可为答主
回答量:2197
采纳率:100%
帮助的人:2631万
展开全部
修改如下:
Private Sub Excle_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) = "竖框款式"
objSheet.Cells(1, 3) = "门扇数"
objSheet.Cells(1, 5) = "色号"

objSheet.Cells(2, 1) = "门洞宽"
objSheet.Cells(3, 1) = "门洞高" '对单元格赋值
objSheet.Cells(4, 1) = "成品门总宽"
objSheet.Cells(5, 1) = "成品门总高"

objSheet.Cells(1, 2) = Combo1.Text
objSheet.Cells(1, 4) = Combo2.Text

objSheet.Cells(2, 2) = Text1.Text
objSheet.Cells(3, 2) = Text2.Text
objSheet.Cells(4, 2) = Text3.Text
objSheet.Cells(5, 2) = Text4.Text

objWorkBook.SaveAs "F:\aa.xls" '保存
objWorkBook.Close
objExcel.Quit
Set objSheet = Nothing
Set objWorkBook = Nothing
Set objExcel = Nothing
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式