2015-10-10 117 views
0

我正在尋找一種方法來檢查MS Access是否安裝,然後如果它不是Exit Sub或完成運行模塊的其餘部分。我遇到了這樣的代碼,但我不確定如何調整它以適應我的需要。檢查MS Access是否安裝

Function ApplicationIsAvailable(ApplicationClassName As String) As Boolean 
' returns True if the application is available 
' example: If Not ApplicationIsAvailable("Outlook.Application") Then Exit Sub  
Dim AnyApp As Object 
    On Error Resume Next 
    Set AnyApp = CreateObject(ApplicationClassName) 
    ApplicationIsAvailable = Not AnyApp Is Nothing 
    Set AnyApp = Nothing 
    On Error GoTo 0 
End Function 

如果有人能夠協助,請提前致謝。

回答

0

我發佈這個問題後不久就開始工作。如果有人好奇,我使用上面的代碼來聲明函數,然後在模塊中聲明我正在運行,我使用這段代碼來確定它是否可用。

If ApplicationIsAvailable("Access.Application") = False Then 
MsgBox ("You must have Microsoft Access installed to use this function") 
Exit Sub 
End If