Microsoft로 로그인
로그인하거나 계정을 만듭니다.
안녕하세요.
다른 계정을 선택합니다.
계정이 여러 개 있음
로그인할 계정을 선택합니다.

요약

Microsoft Windows에서 다른 프로그램을 시작 하는 Visual Basic for Applications 매크로를 ShellExecute() Windows API 함수를 호출할 수 있습니다. 두 번째 명령은 다음과 같은 제한 사항을 해결 하려면 셸 (예: Visual Basic 문) 또는 WinExec() (Windows API 함수) 대신 ShellExecute() 를 사용 합니다.

셸 및 WinExec()를 사용 하 여 파일 이름만 지정 하 여 신청서를 시작할 수 없습니다. 예를 들어, 다음 Shell 문이 실패 합니다.

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

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 기술 자료의 다음 문서를 참조 하려면 아래 문서 번호를 클릭 합니다.

212536 OFF2000: 기술 자료 문서에서 샘플 코드를 실행 하는 방법
Visual Basic for Applications 도움말 보기에 대 한 자세한 내용은 Microsoft 기술 자료의 다음 문서를 참조 하십시오.

226118 OFF2000: Visual Basic for Applications 대 한 프로그래밍 리소스


Microsoft Windows SDK "프로그래머 참조, 볼륨 2: 함수," 페이지 901-904

도움이 더 필요하세요?

더 많은 옵션을 원하세요?

구독 혜택을 살펴보고, 교육 과정을 찾아보고, 디바이스를 보호하는 방법 등을 알아봅니다.

커뮤니티를 통해 질문하고 답변하고, 피드백을 제공하고, 풍부한 지식을 갖춘 전문가의 의견을 들을 수 있습니다.

이 정보가 유용한가요?

언어 품질에 얼마나 만족하시나요?
사용 경험에 어떠한 영향을 주었나요?
제출을 누르면 피드백이 Microsoft 제품과 서비스를 개선하는 데 사용됩니다. IT 관리자는 이 데이터를 수집할 수 있습니다. 개인정보처리방침

의견 주셔서 감사합니다!

×