读书人

大侠请进 vb操作excel有关问题

发布时间: 2012-12-21 12:03:49 作者: rapoo

大侠请进 紧急求助vb操作excel问题
各位大侠好,我现在做一个小程序,我想给一个excel文件里边写数据,但是现在运行后,打开写的那个excel文件的时候提示文件锁定,我在任务管理器里边找到了excel。exe,怎么才能够杀掉那个进程呢?
我手动杀掉进程后,单开文件后看里边没有保存,求各位大侠帮忙解决一下吧!小弟不胜感激,我现在没有分,好心人帮帮忙吧。
源码如下:

Option Explicit
Dim ExlApp As Object
Dim ExlBook As Object
Dim ExlSheet As Object
Dim Row As Long
Dim text_temp1 As String
Dim text_temp2 As String

Private Sub Command1_Click()

If Text3.Text = "" Then
MsgBox "请输入数字。", vbCritical, vbSystemModal
Else
Timer1.Enabled = True

End If
End Sub

Private Sub Command2_Click()
Dim path1 As String
Dim name As String
Timer1.Enabled = False
path1 = "D:\"
name = Text3.Text
ActiveWorkbook.SaveAs path1 & name
'ExlApp.Quit
'Call SaveExcel
ExlBook.Close
ExlApp.Quit
Set ExlSheet = Nothing
Set ExlBook = Nothing
Set ExlApp = Nothing

End Sub

Private Sub Form_Load()

Row = 1

Dim xlsApp As Excel.Application
Dim xlsBook As Excel.Workbook
Dim xlsCurrentSheet As Excel.Worksheet
Set xlsApp = New Excel.Application
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = False
Set xlsBook = xlsApp.Workbooks.Add
Set xlsCurrentSheet = xlsBook.Worksheets("Sheet1")
'If xlsApp = "" Then xlsBook.SaveAs ("C:\tt11.xls")

Set xlsApp = Nothing
Set ExlApp = CreateObject("Excel.Application")
Set ExlBook = ExlApp.Workbooks.Open("C:\tt11.xls")
Set ExlSheet = ExlBook.Worksheets(1)
ExlApp.DisplayAlerts = False
ExlApp.Visible = True
ExlSheet.Cells(1, 1) = "金额"
ExlSheet.Cells(1, 2) = "合计"
ExlApp.ActiveSheet.Rows.HorizontalAlignment = xlVAlignCenter '水平居中

ExlApp.ActiveSheet.Rows.VerticalAlignment = xlVAlignCenter '垂直居中
With ExlApp.ActiveSheet.Range("A1:b1").Font '字体设置

.Size = 18

.Bold = True

.Italic = False

.ColorIndex = 3

End With



End Sub

Private Sub Form_Unload(Cancel As Integer)
' Command2.Click

ExlApp.Quit
Set ExlSheet = Nothing
Set ExlBook = Nothing
Set ExlApp = Nothing
End Sub

Private Sub Timer1_Timer()


text_temp1 = 300
text_temp2 = 600
Row = Row + 1
ExlSheet.Cells(Row, 1).Value = Val(text_temp1)
ExlSheet.Cells(Row, 2).Value = Val(text_temp2)

End Sub

[解决办法]
该回复于2011-07-11 09:44:11被版主删除
[解决办法]
shell "taskkill /IM excel.exe",vbHide
[解决办法]
我最近也有在研究类似项目,加我QQ:1085992075


[解决办法]
我最近也有在研究类似项目,加我QQ:1085992075

[解决办法]
Private Sub Form_Unload(Cancel As Integer)
' Command2.Click

ExlBook Close True'/加这一句退出时保存一下表,那就OK了
ExlApp.Quit
Set ExlSheet = Nothing
Set ExlBook = Nothing
Set ExlApp = Nothing
End Sub

[解决办法]
null

读书人网 >VB

热点推荐