Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

摘要

您可以從 Visual Basic for Applications 巨集,來啟動 Microsoft windows 的另一個程式,以呼叫ShellExecute() Windows API 函式。使用ShellExecute()而不是殼層(Visual Basic 陳述式) 或WinExec() (Windows API 函式),若要解決下列的限制的第二個命令:

殼層和WinExec(),您無法指定檔案名稱來啟動應用程式。例如,下列的殼層陳述式將會失敗:

x = Shell("C:\My Documents\Book1.Xls")

更多的資訊

Microsoft 提供程式設計範例僅供說明,不做任何明示或默示的保證。這包括,但不限於適售性或適合某特定用途之默示擔保責任。本文假設您已相當熟悉使用的我們所示範的程式設計語言以及建立和偵錯程序所使用的工具。Microsoft 技術支援工程師可以協助解釋特定程序中,功能,但它們不會修改這些範例以提供附加功能或建構程序來滿足您特定需求。下面是呼叫ShellExecute() Windows API 函式的巨集的範例 Visual Basic for Applications。ShellExecute()可讓您決定是否 Microsoft Excel 已經在執行;如果是的話,它會將 Book1.xls 載入至目前的 Microsoft Excel 工作階段中。如果尚未執行 Microsoft Excel, ShellExecute()就會啟動 Microsoft Excel,並載入 Book1.xls。

Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long

Declare Function apiFindWindow Lib "User32" Alias "FindWindowA" _
(ByVal lpclassname As Any, ByVal lpCaption As Any) As Long

Global Const SW_SHOWNORMAL = 1

Sub ShellExecuteExample()
Dim hwnd
Dim StartDoc
hwnd = apiFindWindow("OPUSAPP", "0")

StartDoc = ShellExecute(hwnd, "open", "C:\My Documents\Book1.xls", "", _
"C:\", SW_SHOWNORMAL)
End Sub

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×