Solved

Minimize IE After Opening with VB

Posted on 2012-03-23
7
2,046 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
  • 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37760504
Found the answer!

Stand by!

Chris
0
 
LVL 13

Accepted Solution

by:
Chris Raisin earned 500 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

777 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