注册 登录
编程论坛 VB6论坛

将计算结果输出到excel时出错,无法保存

彭林才 发布于 2016-04-24 19:57, 1827 次点击
将计算结果输出到excel时出错,代码如下
只有本站会员才能查看附件,请 登录

Set xlsApp = CreateObject("Excel.Application")
Set xlsworkbook = xlsApp.Workbooks.Open(App.Path & "\jieguo.xls")
xlsApp.Visible = False
Set xlssheet = xlsworkbook.Worksheets.Item(1)
xlssheet.Cells(1, 1) = "起算数据"
xlssheet.Cells(2, 1) = "已知点坐标"
xlssheet.Cells(3, 1) = "   点名   ": xlssheet.Cells(3, 2) = "    X(m)  ": xlssheet.Cells(3, 3) = "   Y(m)   "
If daoxianType = 1 Then
    For i = 1 To 4
        xlssheet.Cells(i + 3, 1) = yzdm(i): xlssheet.Cells(i + 3, 2) = yzzbx(i): xlssheet.Cells(i + 3, 3) = yzzby(i)
    Next
End If
If daoxianType = 0 Then
    For i = 1 To 2
        xlssheet.Cells(i + 3, 1) = yzdm(i): xlssheet.Cells(i + 3, 2) = yzzbx(i): xlssheet.Cells(i + 3, 3) = yzzby(i)
    Next
End If

xlsworkbook.Save
xlsApp.Quit
Set xlsApp = Nothing
 
1 回复
#2
HVB62016-04-25 10:25
试试:
Set xlsApp = CreateObject("Excel.Application")
Set xlsworkbook = xlsApp.Workbooks.Open(App.Path & "\jieguo.xls")
xlsApp.Visible = False
Set xlssheet = xlsworkbook.Worksheets.Item(1)
xlssheet.Cells(1, 1) = "起算数据"
xlssheet.Cells(2, 1) = "已知点坐标"
xlssheet.Cells(3, 1) = "   点名   ": xlssheet.Cells(3, 2) = "    X(m)  ": xlssheet.Cells(3, 3) = "   Y(m)   "
If daoxianType = 1 Then
    For i = 1 To 4
        xlssheet.Cells(i + 3, 1) = yzdm(i): xlssheet.Cells(i + 3, 2) = yzzbx(i): xlssheet.Cells(i + 3, 3) = yzzby(i)
    Next
End If
If daoxianType = 0 Then
    For i = 1 To 2
        xlssheet.Cells(i + 3, 1) = yzdm(i): xlssheet.Cells(i + 3, 2) = yzzbx(i): xlssheet.Cells(i + 3, 3) = yzzby(i)
    Next
End If
xlsApp.Visible = True
  xlsworkbook.Close (True)

'xlsworkbook.Save
xlsApp.Quit
Set xlsApp = Nothing
 
1