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’,类型不匹配”字样。请高手指点。 展开
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’,类型不匹配”字样。请高手指点。 展开
展开全部
修改如下:
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询