小弟不会vb编程,特求大神给个demo,在此感谢! 下面是我在网上找到的例子,运行报错:
Dim ExcelApp As Object Private Sub Form_Unload(Cancel As Integer) Dim X As Integer X = MsgBox("是否保存更改?", vbYesNoCancel + vbExclamation, "VB 保存数据到中 Excel") If X = 6 Then '单击“是”则保存 Set ExcelApp = CreateObject("Excel.Application") ExcelApp.Workbooks.Add With ExcelApp.ActiveSheet .Range("A1:J1") = Array(Text1(0).Text, Text1(1).Text, Text1(2).Text, Text1(3).Text, Text1(4).Text, Text1(5).Text, Text1(6).Text, Text1(7).Text, Text1(8).Text, Text1(9).Text) .Range("A2:J2") = Array(Text1(10).Text, Text1(11).Text, Text1(12).Text, Text1(13).Text, Text1(14).Text, Text1(15).Text, Text1(16).Text, Text1(17).Text, Text1(18).Text, Text1(19).Text) MyFileName = ExcelApp.GetSaveAsFilename(fileFilter:="Excel Files (*.xls), *.xls") .SaveAs MyFileName End With ExcelApp.Quit ElseIf X = 7 Then '单击“否”则不保存 Cancel = 0 Else '单击“取消”则不退出程序 Cancel = 1 End If End Sub