Özet
Microsoft Windows altında başka bir programı başlatmak için bir Visual Basic for Applications makrosu gelen ShellExecute() Windows API işlevi çağırabilirsiniz. ShellExecute() Kabuk (Visual Basic deyimi) veya WinExec() (Windows API işlevi) yerine ikinci komutları aşağıdaki kısıtlamayı aşmak için kullanın:Kabuk ve WinExec()ile yalnızca bir dosya adı belirterek bir uygulama başlatılamıyor. Örneğin, aşağıdaki Kabuk deyimi başarısız olur:
x = Shell("C:\My Documents\Book1.Xls")
Daha fazla bilgi
Microsoft zımni veya açık garanti olmadan programlama örneklerini yalnızca gösterim amacıyla sağlar. Bu, satılabilirlik veya belirli bir amaca uygunluk açısından zımni garantileri içerir ancak bunlarla sınırlı değildir. Bu makale, gösterilen programlama dilini, yordamları oluşturmak ve yordamlardan hata ayıklamak için kullanılan araçları bildiğinizi varsayar. Microsoft destek mühendisleri belirli bir yordamın işlevselliğinin açıklanmasına yardımcı olabilirler, ancak ilave işlevsellik sağlamak için bu örnekleri değiştirmezler veya belirli gereksinimlerinizi karşılayacak şekilde yordamları yapılandırmazlar. Örnek Visual Basic for Applications makrosu ShellExecute() Windows API işlevi çağrıları aşağıdadır. ShellExecute() Microsoft Excel zaten çalışır durumda olup olmadığını belirler; Bu durumda, geçerli Microsoft Excel oturuma Kitap1.xls yükler. Microsoft Excel zaten çalışmıyorsa, ShellExecute() Microsoft Excel'in başlamasını ve Kitap1.xls yükler.
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 LongDeclare Function apiFindWindow Lib "User32" Alias "FindWindowA" _ (ByVal lpclassname As Any, ByVal lpCaption As Any) As LongGlobal Const SW_SHOWNORMAL = 1Sub ShellExecuteExample() Dim hwnd Dim StartDoc hwnd = apiFindWindow("OPUSAPP", "0") StartDoc = ShellExecute(hwnd, "open", "C:\My Documents\Book1.xls", "", _ "C:\", SW_SHOWNORMAL)End Sub
ShellExecute() işlevi açar veya belirtilen dosyaya yazdırır. Aşağıda verilmiştir ShellExecute() hakkında sayfalarındaki bilgiler 901-904, Microsoft Windows Software Development Kit (SDK) "Programmer's Reference, birim 2:Functions."
Parametreleri
Parameter Description--------------------------------------------------------------------------- hwnd Identifies the parent window. lpszOp A string specifying the operation to perform. This string can be "open" or "print". lpszFile Points to a string specifying the file to open. lpszParams Points to a string specifying parameters passed to the application when the lpszFile parameter specifies an executable file. If lpszFile points to a string specifying a document file, this parameter is NULL. lpszDir Points to a string specifying the default directory. fsShowCmd Specifies whether the application window is to be shown when the application is opened. This parameter can be one of the following values: Value Meaning --------------------------------------------------------------------- 0 Hides the window and passes activation to another window. 1 Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position (same as 9). 2 Activates a window and displays it as an icon. 3 Activates a window and displays it as a maximized window. 4 Displays a window in its most recent size and position. The window that is currently active remains active. 5 Activates a window and displays it in its current size and position. 6 Minimizes the specified window and activates the top-level window in the system's list. 7 Displays a window as an icon. The window that is currently active remains active. 8 Displays a window in its current state. The window that is currently active remains active. 9 Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position (same as 1).
Döndürür
İşlev başarılı olursa dönüş değeri açıldığında veya yazdırılan, uygulamanın örneğini işleyicisidir. (Bu tutamacı tutamaç, DDE sunucu uygulamasını da olabilir.) Bir dönüş değeri küçük veya eşit 32 hata belirtir.
Hataları
ShellExecute() işlevi, belirtilen dosya türü ilişkilendirmesi yok ise veya belirtilen eylem içinde dosya türü ilişkilendirmesi yok ise 31 değeri döndürür. Diğer olası hata değerleri aşağıdaki gibidir:Value Meaning--------------------------------------------------------------------------- 0 System was out of memory, executable file was corrupt, or relocations were invalid. 2 File was not found. 3 Path was not found. 5 Attempt was made to dynamically link to a task, or there was a sharing or network-protection error. 6 Library required separate data segments for each task. 8 There was insufficient memory to start the application. 10 Windows version was incorrect. 11 Executable file was invalid. Either it was not a Windows application, or there was an error in the .exe image. 12 Application was designed for a different operating system. 13 Application was designed for MS-DOS 4.0. 14 Type of executable file was unknown. 15 Attempt was made to load a real-mode application (developed for an earlier version of Windows). 16 Attempt was made to load a second instance of an executable file containing multiple data segments that were not marked read-only. 19 Attempt was made to load a compressed executable file. The file must be decompressed before it can be loaded. 20 Dynamic-link library (DLL) file was invalid. One of the DLLs required to run this application was corrupt. 21 Application requires Microsoft Windows 32-bit extensions.
Yorumlar
LpszFile parametresi tarafından belirtilen dosya, bir belge dosyası veya çalıştırılabilir bir dosya olabilir. Belge dosyası ise, bu işlev açar veya, lpszOp parametresinin değerine bağlı olarak yazdırır. Yürütülebilir bir dosya ise, dize "Yazdır" olarak lpszOp tarafından verilir, bu işlev, açar.
Başvurular
Bu makaledeki örnek kodu kullanma hakkında daha fazla bilgi için Microsoft Bilgi Bankası'ndaki makaleyi görüntülemek üzere aşağıdaki makale numarasını tıklatın:
212536 OFF2000: Bilgi Bankası makalelerindeki örnek kodu çalıştırmaUygulamalar için Visual Basic Yardımı alma hakkında daha fazla bilgi için lütfen aşağıdaki Microsoft Bilgi Bankası makalesine bakın:
226118 OFF2000: Visual Basic for Applications programlama kaynaklarıMicrosoft Windows SDK "Programmer's Reference Volume 2: İşlevler," 901-904 sayfalar