Results 1 to 13 of 13

Thread: close window

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    close window

    I dont know much about Visual Basic, but here is what I have:

    Sub Macro1()

    For x = 1 To 10
    ActiveDocument.FollowHyperlink Address:="http://www.spftservers.com", _
    NewWindow:=False, AddHistory:=True

    Next x

    End

    End Sub

    That basicallly opens up an internet explorer window during the loop. What I want it to do is close that internet explorer window after it is opened. Also, I would preferably like it to wait 2 seconds before closing the window. I need the code for the program since I dont know much. Thank you.

    Here is what my total program is to do, so if you can write better code...:

    1. Open a new Mozilla/Internet Window
    2. Go to a certain website
    3. **Optional** Wait 5 seconds
    3. Close that Window
    4. Have a loop with a certain amount runs

    Thanks

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: close window

    Welcome to the Forums.

    Are you doing this in Word's VBA?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: close window

    yes i am

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: close window

    Why do you need it to open to the same url many times?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: close window

    im running a test for my network, and then my office.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: close window

    Looks like your going to have to use some APIs to FindWindow of the correct browser instance and then PostMessage to close it. You can download the API declarations from allapi.net for the API Viewer utility.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: close window

    how do i do those? sorry im a beginner at this

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: close window

    ok i got both of these could someone please help me put it together

    Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long


    Declare Function CloseWindow Lib "user32.dll" ( _
    ByVal hwnd As Long) As Long

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: close window

    The class name for IE is "IEFrame" so it depends on the browser your looking to close. Is it IE or FF or ??
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: close window

    OK i have this:

    Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long

    Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
    ByVal hWnd1 As Long, _
    ByVal hWnd2 As Long, _
    ByVal lpsz1 As String, _
    ByVal lpsz2 As String) As Long

    Declare Function CloseWindow Lib "user32.dll" ( _
    ByVal hWnd As Long) As Long



    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 1/4/2006 by yes
    '
    For y = 1 To 10

    For x = 1 To 1000
    ActiveDocument.FollowHyperlink Address:="http://www.spftservers.com", _
    NewWindow:=True, AddHistory:=True

    Dim lIEFramehWnd As Long
    lIEFramehWnd = FindWindow("IEFrame", vbNullString)




    Next x

    Next y

    End

    This should find the IE window, now how do i close it?

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: close window

    You dont need the FindWindowEx as its only for child windows.
    VB Code:
    1. Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    2. ByVal lpClassName As String, _
    3. ByVal lpWindowName As String) As Long
    4.  
    5. Declare Function CloseWindow Lib "user32.dll" ( _
    6. ByVal hWnd As Long) As Long
    7.  
    8. Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    9.  
    10. Sub Macro1()
    11. '
    12. ' Macro1 Macro
    13. ' Macro recorded 1/4/2006 by yes
    14. '
    15. Dim lIEFramehWnd As Long
    16.  
    17. For y = 1 To 10
    18.     For x = 1 To 1000
    19.         ActiveDocument.FollowHyperlink Address:="http://www.spftservers.com", _
    20.         NewWindow:=True, AddHistory:=True
    21.         'Make a pause
    22.         Sleep 5000
    23.         lIEFramehWnd = FindWindow("IEFrame", vbNullString)
    24.         If lIEFramehWnd <> 0 Then
    25.             CloseWindow lIEFramehWnd
    26.         Else
    27.             MsgBox "Cant Find IE"
    28.         End If
    29.     Next
    30. Next
    31.  
    32. End
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: close window

    ok its working, but except for closing them, its just minimizing them

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: close window

    I was unsure about that API but the PostMessage that I originally suggested will work.
    VB Code:
    1. Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    2. ByVal wParam As Long, ByVal lParam As Long) As Long
    3.  
    4. Private Const WM_QUIT As Long = &H12
    5. Private Const WM_CLOSE As Long = &H10
    6.  
    7. 'Example usage
    8. PostMessage lIEFramehWnd, WM_QUIT, 0&, 0&
    9.  
    10. 'Or
    11. PostMessage lIEFramehWnd, WM_CLOSE, 0&, 0&
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width