דלג לתוכן הראשי
היכנס דרך Microsoft
היכנס או צור חשבון.
שלום,
בחר חשבון אחר.
יש לך חשבונות מרובים
בחר את החשבון שברצונך להיכנס באמצעותו.

סיכום

ניתן לקרוא לפונקציה Windows API ShellExecute() מתוך Visual Basic עבור יישומים מאקרו כדי להפעיל תוכנית אחרת תחת Microsoft Windows. השתמש ShellExecute() במקום מעטפת (משפט Visual Basic) או WinExec() (פונקציה Windows API) כדי לעקוף מגבלה הבאים של פקודות האחרון:

עם מעטפת ו- WinExec(), אין באפשרותך להפעיל יישום על-ידי ציון שם קובץ בלבד. לדוגמה, המשפט הבא של מעטפת תיכשל:

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

מידע נוסף

מיקרוסופט מציעה דוגמאות תכנות לצורך ההדגמה בלבד, ללא אחריות, בין מפורשת ובין משתמעת. זה כולל, אך אינו מוגבל ל, אחריות מכללא לגבי סחירות או התאמה למטרה מסוימת. מאמר זה מבוסס על ההנחה שאתה מכיר את שפת התכנות המודגמת ובקי בהפעלת הכלים המשמשים ליצירת פרוצדורות ולניפוי שגיאות. מהנדסי התמיכה של Microsoft יכולים לסייע בהסברת הפונקציונליות של פרוצדורה מסוימת, אך הם לא ישנו את הדוגמאות כדי לספק פונקציונליות נוספת או כדי לבנות פרוצדורות שיענו על צרכיך הספציפיים. להלן הוא מדגם Visual Basic עבור מאקרו יישומים אשר קוראת לפונקציה Windows API של ShellExecute() . 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

הפונקציה ShellExecute() פותח או מדפיס את הקובץ שצוין. להלן הוא מידע אודות ShellExecute() מדפים 901-904 של Microsoft Windows ערכת פיתוח תוכנה (SDK) "אסמכתא מתכנתים, אמצעי האחסון 2:Functions."

פרמטרים

                
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).

החזרות

הערך המוחזר הוא נקודת האחיזה מופע של יישום לפתוח או מודפס, אם הפונקציה הושלמה בהצלחה. (נקודת אחיזה זו היתה גם להיות נקודת האחיזה של יישום שרת DDE). החזרה ערך קטן או שווה ל- 32 מציין שגיאה.

שגיאות

הפונקציה ShellExecute() מחזירה את הערך 31 אם אין שיוך עבור סוג הקובץ שצוין או אם אין שיוך עבור הפעולה שצוינה בתוך סוג הקובץ. ערכי השגיאה אפשריות אחרות הן כדלקמן:


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.

הערות

הקובץ שצוין על-ידי הפרמטר lpszFile יכול להיות קובץ מסמך או קובץ הפעלה. אם הקובץ הוא קובץ המסמך, פונקציה זו פותח או מדפיס אותו, בהתאם לערך הפרמטר lpszOp. אם הוא קובץ הפעלה, פונקציה זו פותחת אותה, גם אם המחרוזת "הדפס" מצביעים על-ידי lpszOp.

הפניות

לקבלת מידע נוסף אודות אופן השימוש בקוד לדוגמה במאמר זה, לחץ על מספר המאמר שלהלן כדי להציג את המאמר הרלוונטי מתוך Microsoft Knowledge Base:

212536 OFF2000: כיצד להפעיל קוד לדוגמה מתוך מאמרי Knowledge Base
לקבלת מידע נוסף אודות קבלת עזרה עם Visual Basic ליישומים, נא עיין במאמר הבא מתוך מאגר הידע Microsoft Knowledge Base:

226118 OFF2000: משאבים תיכנות עבור Visual Basic for Applications


Microsoft Windows SDK "אסמכתא מתכנתים, אמצעי אחסון 2: פונקציות," דפי 901-904

זקוק לעזרה נוספת?

מעוניין באפשרויות נוספות?

גלה את יתרונות המנוי, עיין בקורסי הדרכה, למד כיצד לאבטח את המכשיר שלך ועוד.

קהילות עוזרות לך לשאול שאלות ולהשיב עליהן, לתת משוב ולשמוע ממומחים בעלי ידע עשיר.

האם מידע זה היה שימושי?

עד כמה אתם מרוצים מאיכות השפה?
מה השפיע על החוויה שלך?
בלחיצה על 'שלח', אתה מאפשר למשוב שלך לשפר מוצרים ושירותים של Microsoft. מנהל ה-IT שלך יוכל לאסוף נתונים אלה. הצהרת הפרטיות.

תודה על המשוב!

×