Word 2000: Hoe u de functie ShellExecute van Windows API aanroepen

Artikel ID: 238245 - Bekijk de producten waarop dit artikel van toepassing is.
Alles uitklappen | Alles samenvouwen

Op deze pagina

Samenvatting

U kunt oproepen deShellExecute ()Windows API-functie vanuit een Visual Basic for Applications-macro om een ander programma onder Microsoft Windows te starten. GebruikShellExecute ()in plaats vanShell(een Visual Basic-instructie) ofWinExec()(een Windows API-functie) van de laatste opdrachten de volgende beperking omzeilen:

MetShellenWinExec(), u een toepassing niet starten door alleen een bestandsnaam opgeven. Bijvoorbeeld de volgendeShellinstructie mislukken:
x = Shell("C:\My Documents\Book1.Xls")
				

Meer informatie

Microsoft biedt program meer voorbeelden ter illustratie alleen, zonder expliciete of impliciete garantie. Dit omvat, maar is niet beperkt tot, de impliciete garanties van verkoopbaarheid of geschiktheid voor een bepaald doel. In dit artikel wordt ervan uitgegaan dat u bekend met de programmeer taal worden opgespoord en met de hulp programma's die worden gebruikt bent voor het maken en waarmee fouten in procedures. Ondersteuningstechnici van Microsoft kunnen helpen verklaren de functionaliteit van een bepaalde procedure, maar zij zal deze voorbeelden om extra functionaliteit of samens tellen van procedures om te voldoen aan uw specifieke vereisten niet wijzigen.Hieronder ziet u een voorbeeld van Visual Basic for Applications-macro roept deShellExecute ()Windows API-functie.ShellExecute ()Hiermee bepaalt u of Microsoft Excel reeds actief is; in dat geval wordt Map1. xls in de huidige sessie van Microsoft Excel geladen. Als Microsoft Excel nog niet actief is,ShellExecute ()Start Microsoft Excel en laadt Book1.
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
				
HetShellExecute ()functie opent of het opgegeven bestand wordt afgedrukt. Hieronder volgt informatie over ShellExecute () van 901 904 pagina's van de Microsoft Windows Software Development Kit (SDK) "Programmer's Reference, Volume 2:Functions."

Parameters

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

Geeft als resultaat

De retour waarde is de sessiehandler van de toepassing die werd geopend of afgedrukt, als de functie voltooid is. (Deze ingang kan ook worden de greep van een DDE-servertoepassing.) Een retour waarde die kleiner dan of gelijk aan 32 geeft een fout.

Fouten

HetShellExecute ()de waarde 31 geretourneerd als er geen koppeling voor het opgegeven bestandstype of als er geen koppeling voor de opgegeven actie binnen het bestandstype. De andere mogelijke foutwaarden zijn als volgt:
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.
				

Opmerkingen

Het bestand dat is opgegeven door de parameter lpszFile kan een document bestand of een uitvoerbaar bestand. Als het bestand is, wordt deze functie opent of afdrukt, afhankelijk van de waarde van de parameter lpszOp. Als een uitvoerbaar bestand is, opent deze functie, zelfs als de teken reeks "afdrukken" wordt aangewezen door de lpszOp.

Referenties

Klik voor meer informatie over het gebruik van de voorbeeldcode in dit artikel het volgende artikelnummer om het artikel in de Microsoft Knowledge Base te bekijken:
212536Office 2000: Hoe u voorbeeldcode uit Knowledge Base-artikelen uitvoeren
Voor meer informatie over het opvragen van help voor Visual Basic for Applications, Raadpleeg het volgende artikel in de Microsoft Knowledge Base:
226118Office 2000: Programmeren bronnen voor Visual Basic for Applications


Microsoft Windows SDK "Programmer's Reference, Volume 2: functies," 901 904 pagina's

Eigenschappen

Artikel ID: 238245 - Laatste beoordeling: zondag 18 september 2011 - Wijziging: 3.0
De informatie in dit artikel is van toepassing op:
  • Microsoft Word 2000 Standard Edition
Trefwoorden: 
kbhowto kbprogramming kbmt KB238245 KbMtnl
Automatische vertaling
BELANGRIJK: Dit artikel is vertaald door de vertaalmachine software van Microsoft in plaats van door een professionele vertaler. Microsoft biedt u professioneel vertaalde artikelen en artikelen vertaald door de vertaalmachine, zodat u toegang heeft tot al onze knowledge base artikelen in uw eigen taal. Artikelen vertaald door de vertaalmachine zijn niet altijd perfect vertaald. Deze artikelen kunnen fouten bevatten in de vocabulaire, zinsopbouw en grammatica en kunnen lijken op hoe een anderstalige de taal spreekt en schrijft. Microsoft is niet verantwoordelijk voor onnauwkeurigheden, fouten en schade ontstaan door een incorrecte vertaling van de content of het gebruik ervan door onze klanten. Microsoft past continue de kwaliteit van de vertaalmachine software aan door deze te updaten.
De Engelstalige versie van dit artikel is de volgende:238245

Geef ons feedback