1. FAQ
  2. 엑셀(Excel)
  3. AfterEffects
  4. Premiere
  5. Photoshop
  6. ETC

이 게시판은 아별닷컴 회원만 질문을 올릴 수 있습니다. 회원에게 주어지는 특권인셈이지요. 회원이 아닌 분들은 열람만 가능합니다.

[레벨:30]아별

2013.04.08 15:57

맑은이슬님..

참고로 링크해주신 곳의 코드를 테스트해보니..

잘 동작하는데요? ^_^;;


코드 아래 쪽에 test프로시저를 보시면.. 아래처럼 되어 있죠?

캡션명이 "Microsoft Internet Explorer"인 인터넷 익스플로러 창을 닫으라는 의미입니다.


Sub test()

    CloseApp "Microsoft Internet Explorer", "IEFrame"

End Sub


저걸 아래처럼 수정하면.. 캡션명이 "네이버"로 시작되는 인터넷 익스플로러 창을 닫아줍니다.

Sub test()

    CloseApp "네이버", "IEFrame"

End Sub


인터넷 익스플로러에서 네이버로 들어가신 다음 첨부파일을 실행해보세요..


다운받기 : VBA_인터넷익스플로러창닫기_closeIE.xlsm


Option Explicit


'### From. http://www.excelforum.com/excel-programming-vba-macros/475166-using-excel-vba-to-close-ie.html

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _

    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private Declare Function GetWindow Lib "user32" _

    (ByVal hwnd As Long, ByVal wCmd As Long) As Long

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _

    (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _

    (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Private Const GW_HWNDFIRST = 0

Private Const GW_HWNDLAST = 1

Private Const GW_HWNDNEXT = 2

Private Const GW_HWNDPREV = 3

Private Const GW_OWNER = 4

Private Const GW_CHILD = 5

Private Const WM_CLOSE = &H10


Function FindWindowHwndLike(hWndStart As Long, ClassName As String, _

        WindowTitle As String, level As Long, lHolder As Long) As Long

    'finds the first window where the class name start with ClassName

    'and where the Window title starts with WindowTitle, returns Hwnd

    '----------------------------------------------------------------

    Dim hwnd As Long

    Dim sWindowTitle As String

    Dim sClassName As String

    Dim r As Long

    'Initialize if necessary. This is only executed

    'when level = 0 and hWndStart = 0, normally

    'only on the first call to the routine.

    If level = 0 Then

        If hWndStart = 0 Then

            hWndStart = GetDesktopWindow()

        End If

    End If

    'Increase recursion counter

    level = level + 1

    'Get first child window

    hwnd = GetWindow(hWndStart, GW_CHILD)

    Do Until hwnd = 0

        'Search children by recursion

        lHolder = FindWindowHwndLike(hwnd, ClassName, _

                    WindowTitle, level, lHolder)

        'Get the window text

        sWindowTitle = Space$(255)

        r = GetWindowText(hwnd, sWindowTitle, 255)

        sWindowTitle = Left$(sWindowTitle, r)

        'get the class name

        sClassName = Space$(255)

        r = GetClassName(hwnd, sClassName, 255)

        sClassName = Left$(sClassName, r)

        If InStr(1, sWindowTitle, WindowTitle, vbBinaryCompare) > 0 And _

            sClassName Like ClassName & "*" Then

            FindWindowHwndLike = hwnd

            lHolder = hwnd

            Exit Function

        End If

        'Get next child window

        hwnd = GetWindow(hwnd, GW_HWNDNEXT)

    Loop

    FindWindowHwndLike = lHolder

End Function


Function CloseApp(ByVal strApp As String, _

                  ByVal strClass As String) As Long

    'will find a window based on:

    'the partial start of the Window title and/or

    'the partial start of the Window class

    'and then close that window

    'for example, this will close Excel:

    'CloseApp "", "XLM" and this will:

    'CloseApp "Microsoft Excel", ""

    'but this won't: CloseApp "", "LM"

    'it will only close the first window that

    'fulfills the criteria

    'will return Hwnd if successfull, and 0 if not

    '---------------------------------------------

    Dim hwnd As Long

    On Error GoTo ERROROUT

    hwnd = FindWindowHwndLike(0, strClass, strApp, 0, 0)

    If hwnd = 0 Then

        CloseApp = 0

        Exit Function

    End If

    'Post a message to the window to close itself

    '--------------------------------------------

    PostMessage hwnd, WM_CLOSE, 0&, 0&

    CloseApp = hwnd

    Exit Function

ERROROUT:

    On Error GoTo 0

    CloseApp = 0

End Function



Sub abCloseIEwithNaver()

    'CloseApp "Microsoft Internet Explorer", "IEFrame"

    CloseApp "네이버", "IEFrame"

    CloseApp "네이버", "Chrome_WidgetWin_1"

    CloseApp "네이버", "{1C03B488-D53B-4a81-97F8-754559640193}"

End Sub


Sub abNavigateNaver()

    ActiveSheet.Hyperlinks.Add Anchor:=Range("B2"), Address:= _

        "http://www.naver.com/", TextToDisplay:="http://www.naver.com/"

    Range("B2").Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True

End Sub 



문서 첨부 제한 : 0Byte/ 2.00MB
파일 제한 크기 : 2.00MB (허용 확장자 : *.*)