我正在用 Outlook VBA 为自己编写一种自制的票务系统,并使用 Excel 存储所有持久数据。我在 Outlook 中编写了一个函数,用于从 .csv 中获取一些数据...
我正在用 Outlook VBA 为自己编写一种自制的票务系统,并使用 Excel 存储所有持久数据。我在 Outlook 中编写 ,用于从 .csv 获取一些数据并返回。这一切都运行正常,但在我关闭工作簿、退出应用程序并将应用程序设置为无后,我仍然有一个 Excel 进程在运行!这是我的代码:
Private Function GetNewTicketNumber() As Integer
Dim xlApp As Excel.Application
Set xlApp = New Excel.Application
With xlApp
.Visible = False
.EnableEvents = False
.DisplayAlerts = False
End With
Dim FileStr As String
Dim NumberBook As Workbook
Dim TheRange As Range
FileStr = "C:\OMGITSAPATH.csv"
Set NumberBook = Workbooks.Open(FileStr)
Set TheRange = NumberBook.Worksheets(1).Range("A1")
GetNewTicketNumber = TheRange.Value
TheRange.Value = TheRange.Value + 1
NumberBook.Save
NumberBook.Close
xlApp.Quit
With xlApp
.Visible = True
.EnableEvents = True
.DisplayAlerts = True
End With
Set xlApp = Nothing
End Function
Private Function GetNewTicketNumber() As Long
Dim xlApp As Object
Dim objWB As Object
Dim objWs As Object
Dim FileStr As String
FileStr = "C:\temp\test.xlsx"
Set xlApp = CreateObject("excel.application")
With xlApp
.EnableEvents = False
.DisplayAlerts = False
End With
Set objWB = xlApp.Workbooks.Open(FileStr)
Set objWs = objWB.Sheets(1)
GetNewTicketNumber = objWs.Range("A1")
objWs.Range("A1") = objWs.Range("A1") + 1
objWB.Save
objWB.Close
Set objWB = Nothing
xlApp.Quit
Set xlApp = Nothing
End Function