?
Solved

Minimize IE After Opening with VB

Posted on 2012-03-23
7
Medium Priority
?
2,483 Views
Last Modified: 2012-03-27
Hi - I am opening internet explorer using Set ie = CreateObject("internetexplorer.application").  I know how to make it visible or not, but I cannot figure out how to minimize the window once it is open.  

I would like to have IE minimize to the taskbar so that a user can easily maximize it if needed.  

Thanks in advance for your help!
0
Comment
Question by:rsburge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37759799
try using Shell, this is for Windows 7  OS

Shell "C:\Program Files (x86)\Internet Explorer\iexplore.exe", vbMinimizedFocus

in win XP


Shell "C:\Program Files\Internet Explorer\iexplore.exe", vbMinimizedFocus
0
 

Author Comment

by:rsburge
ID: 37759834
Thank you!

Would I put this in place of Set ie = CreateObject("internetexplorer.application")

and instead use

Set ie = Shell "C:\Program Files (x86)\Internet Explorer\iexplore.exe", vbMinimizedFocus  

Can I still manipulate internet explorer using the other commands; for example...

ie.navigate "website"
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37760433
Renee,

It is better not to shell.

Use instead code like the following since you have more internal control over the object and can do lots with it whereas shelling will create an external object over which you then have no further control.

Refer to:
http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx

for properties, methods and events.

You will NOT be able to use "IE.navigate"  etc. if you shell.

Stand by while I check out minimization.....

   Dim IE As SHDocVw.InternetExplorer

  Set IE = CreateObject("InternetExplorer.Application")

  IE.Visible = False  'Note you may need IE to be visible to activate some methods
                              'it is just a matter of try it and see.....

  ........
  ........
 ........

Open in new window

0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37760504
Found the answer!

Stand by!

Chris
0
 
LVL 13

Accepted Solution

by:
Chris Raisin earned 2000 total points
ID: 37760625
OK - Forget the "CreateObject" idea. It is too difficult to invoke a minimization.

Go instead with the following.

I gather you are using the Access Editor with VBA so you will need to add a reference to
"Microsoft Internet Controls" under the menu item in the "Access" menu  "Tools/References".

The following code opens an Internet Explorer, navigates to the website called "Eastern Contract Bridge Centre" (which I own and run) and then minimizes to the Status Bar.
The test code that kicks it off is called (strangely enough) "Test"

This will give you the skeleton on which to frame your own code.

Be aware,though, that if the website you are loading changes the title in their webpage you would have to tweak the code at the time of the change. It would be noticeable because the page would NOT minimize after loading.

I hope that is what you are after.

Cheers
Chris

Option Compare Database
Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) 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 GetParent Lib "user32" (ByVal hWnd As Long) As Long
Private Const GW_HWNDNEXT = 2
Private Const SW_SHOWMINIMIZED = 2

'all the following are not needed, but they are just here in case of need :-)
Enum READYSTATE
    READYSTATE_UNINITIALIZED = 0
    READYSTATE_LOADING = 1
    READYSTATE_LOADED = 2
    READYSTATE_INTERACTIVE = 3
    READYSTATE_COMPLETE = 4
End Enum

Public Sub Test()
  Dim ie As New InternetExplorer
  LoadAndMinimize ie, "www.ecbc.net.au", "Eastern Contract Bridge Centre"
End Sub

Public Sub LoadAndMinimize(ie As InternetExplorer, strUrl As String, strCaption As String)
  
  'strURL is the URL of the webpage to which you are navigating.
  
  'strCaption is a portion of the Web Pages Caption
  '(you do not have to put in all of it, but just enough so that the program
  'finds the correct window to minimize....make it distinct enough to ensure
  'that the program runs no risk of finding another window with the same caption).
  
  ie.Navigate strUrl
  Do While ie.READYSTATE <> READYSTATE_COMPLETE
    DoEvents
  Loop
  MinimizeWindow strCaption
End Sub

Public Sub MinimizeWindow(TitleContains As String)
   Dim hWndApp As Long
   Dim nRet As Long
   hWndApp = FindWindowPartial(TitleContains)
   If hWndApp Then
     nRet = ShowWindow(hWndApp, SW_SHOWMINIMIZED)
   End If
End Sub

Public Function FindWindowPartial(TitleStart As String) As Long
   Dim hWndTmp As Long
   Dim nRet As Long
   Dim TitleTmp As String
   hWndTmp = FindWindow(vbNullString, vbNullString)
   Do Until hWndTmp = 0
      If GetParent(hWndTmp) = 0 Then
         TitleTmp = Space(256)
         nRet = GetWindowText(hWndTmp, TitleTmp, Len(TitleTmp))
         If nRet Then
            TitleTmp = UCase(Left(TitleTmp, nRet))
            If InStr(TitleTmp, UCase(TitleStart)) Then
                FindWindowPartial = hWndTmp
                Exit Do
            End If
        End If
      End If
      hWndTmp = GetWindow(hWndTmp, GW_HWNDNEXT)
   Loop
End Function

Open in new window

0
 

Author Comment

by:rsburge
ID: 37760913
Thanks Chris!  I will test this out tomorrow, but it looks like it will be perfect!

Have a great day!
Renee
0
 

Author Comment

by:rsburge
ID: 37765873
Hi - This seems to work great.  I want to test it in production today to make sure I don't run into any additional questions and then I will close this out.

As always, thanks for all of your help!
Renee
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question