简体   繁体   English

Access使用vba停止excel的后台进程

[英]Access stops background process of excel with vba

I wrote a code that opens a excel file and reads a specific field.我编写了一个代码来打开一个 excel 文件并读取一个特定的字段。 The problem is that every time I execute this code, in the background starts an excel process, the user does not see it, but when you start the Task Manager, you see an excel process.问题是我每次执行这段代码,在后台启动一个excel进程,用户看不到,但是当你启动任务管理器的时候,你看到了一个excel进程。 I want to close this background process with VBA.我想用 VBA 关闭这个后台进程。 I already tried a lot of different things, but nothing really functions.我已经尝试了很多不同的东西,但没有真正起作用。 I already tried:我已经尝试过:

wb.Close
xcelapp.Application.Quit
Set excelapp = Nothing
Set wb = Nothing

Does any one knows how to close excel with vba?有谁知道如何用vba关闭excel?

      `Private Sub Command46_Click()
    Dim wert As String

    Dim sfdcID As String
    Dim excelapp As Object
    Dim wb As Object

    wbName = Combo39.Column(0)
    Pfad = "C:\Users\XXXXXX
    Details = "Delivery Input"

    'Open excel
    Set excelapp = CreateObject("excel.application")
    Set wb = excelapp.Workbooks.Open(Pfad)

    'read SFDC Opportunity ID
    Workbooks(wbName).Sheets(Details).Select
    Cells.Find(What:="COMPASS WBS ID").Activate
    ActiveCell.Offset(1, 0).Select
    sfdcID = Selection
    MsgBox sfdcID     

    End Sub`

If you already have an Excel process running, your code will add yet another.如果您已经有一个 Excel 进程在运行,您的代码将添加另一个。 Try this:尝试这个:

Sub OpenAndCloseExcel()
    Dim XL As Object        'Excel.Application
    Dim WB As Object        'Excel.Workbooks

    Set XL = GetExcel()

        '... do your thing 

    XL.Quit
    Set XL = Nothing
End Sub

'****************************************
'* Get an Excel instance
'*
Function GetExcel() As Object
    Dim XL As Object        'Excel.Application

    On Error Resume Next

    Set XL = GetObject(, "Excel.Application")
    If XL Is Nothing Then Set XL = CreateObject("Excel.Application")
    Set GetExcel = XL  
End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM