Solved

Minimize IE After Opening with VB

Posted on 2012-03-23
7
1,893 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 119

Expert Comment

by:Rey Obrero
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now