sinat_38398702
sinat_38398702
采纳率100%
2017-05-17 05:50

VB中引用EXCEL填表格,生成的EXE文件报错

200
已采纳

在VB6.0编译环境能打开excel ,但生成exe文件后,就报错图片说明

 Option Explicit
Dim newxls As New Excel.Application
Dim newbooks As New Excel.Workbook
Dim newsheet As New Excel.Worksheet
Dim j As Integer
Dim i As Integer

Private Sub Command1_Click()
Text1.Enabled = True
Command4.Visible = True
End Sub

Private Sub Command2_Click()
newxls.Workbooks.Open App.Path & "\EN样式表格.xlsx"
Set newsheet = newxls.Worksheets(1)
Call exinput
Label1.Caption = "共进行" & i & "项"
Label2.Caption = "未通过" & j & "项"
If j < 1 Then
Label5.Caption = "通过认证"
MsgBox ("通过认证")
Image1.Picture = LoadPicture(App.Path & "\image\10-1.ico")
Else
Label5.Caption = "未通过认证"
MsgBox ("未通过认证")
Image1.Picture = LoadPicture(App.Path & "\image\10-2.ico")
End If
Command5.Enabled = True
newxls.Visible = True
Command2.Enabled = False
End Sub

Private Sub Command3_Click()
Form6.Show
newxls.Quit
Set newsheet = Nothing
Set newbooks = Nothing
Set newxls = Nothing
Unload Form13
End
End Sub

Private Sub Command4_Click()
Text1.Text = ""
Text1.Enabled = False
Command4.Visible = False
End Sub

Private Sub Command5_Click()
newxls.Quit
Set newsheet = Nothing
Set newbooks = Nothing
Set newxls = Nothing
End Sub



Private Sub Form_Load()
Text1.Text = enbz
Form13.Height = 5940
Command5.Enabled = False
Text1.Enabled = False
Command4.Visible = False
j = 0
End Sub


Sub exinput()
newsheet.Range("B2").Value = gsname
newsheet.Range("E2").Value = czyname
newsheet.Range("C3").Value = wginfor(0)
newsheet.Range("E3").Value = wginfor(1)
newsheet.Range("G3").Value = wginfor(2)
newsheet.Range("C4").Value = wginfor(5)
newsheet.Range("E4").Value = wginfor(6)
newsheet.Range("G4").Value = wginfor(3)
newsheet.Range("I4").Value = wginfor(4)
newsheet.Range("H2").Value = Year(Now) & "年" & Month(Now) & "月" & Day(Now) & "日"
i = 0
Adodc1.Recordset.MoveFirst
Do Until Adodc1.Recordset.EOF
newsheet.Cells(6 + i, 2) = DataGrid1.Columns(0)
newsheet.Cells(6 + i, 3) = DataGrid1.Columns(1)
newsheet.Range(Cells(6 + i, 4), Cells(6 + i, 7)).Merge
newsheet.Cells(6 + i, 4) = DataGrid1.Columns(2).Text
newsheet.Range(Cells(6 + i, 8), Cells(6 + i, 9)).Merge
If DataGrid1.Columns(3) < 0 Then
newsheet.Cells(6 + i, 8) = "满足"
Else
newsheet.Cells(6 + i, 8) = "不满足"
j = j + 1
End If
i = i + 1
Adodc1.Recordset.MoveNext
Loop

newsheet.Range(Cells(6 + i, 2), Cells(6 + i, 9)).Merge
newsheet.Range(Cells(6, 1), Cells(6 + i, 1)).Merge
newsheet.Cells(7 + i, 1) = "备注"
newsheet.Range(Cells(7 + i, 2), Cells(7 + i, 9)).Merge
newsheet.Cells(7 + i, 2).Interior.ColorIndex = 20
newsheet.Cells(7 + i, 2) = Text1.Text
newsheet.Cells(8 + i, 1) = "认证结果"
newsheet.Range(Cells(8 + i, 2), Cells(8 + i, 7)).Merge
If j > 0 Then
newsheet.Range(Cells(8 + i, 8), Cells(8 + i, 9)).Merge
newsheet.Cells(8 + i, 8) = "未通过认证"
newsheet.Cells(8 + i, 2).Select
newsheet.Pictures.Insert (App.Path & "\image\10-2.ico")
Else
newsheet.Range(Cells(8 + i, 8), Cells(8 + i, 9)).Merge
newsheet.Cells(8 + i, 8) = "通过认证"
newsheet.Cells(8 + i, 2).Select
newsheet.Pictures.Insert (App.Path & "\image\10-1.ico")
End If
newsheet.Range(Cells(1, 1), Cells((8 + i), 9)).Borders.LineStyle = 1
newsheet.Range(Cells(1, 1), Cells((8 + i), 9)).Borders.Weight = 3
newsheet.Shapes(1).Height = 20

End Sub

神啊救救我吧

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • sinat_38398702 sinat_38398702 4年前

    折腾半天好像找到问题所在了 删除newsheet.Pictures.Insert (App.Path & "\image\10-1.ico")相关语句

    点赞 评论 复制链接分享
  • sinat_38398702 sinat_38398702 4年前

    图片说明

    点赞 评论 复制链接分享

相关推荐