Script to auto tab between 2 differnet screen ever 2 mins

Hello I have a single monitor that needs to display 2 different screens at 2 min intervals
screen 1 needs to be maximised and displaying the internet explorer screen for 2 min then minimise or close then screen 2 needs to be maximised and displaying some real time data from a program for 2 mins then minimise or close for 2 mins , this action needs to continually loop ,
Maybe even alt+tab commands could be used to switch between each open screen ever 2 mins

Any help would be appreciated
Who is Participating?
David LeeConnect With a Mentor Commented:
Hi, transpennine.

Here's how to do this.
Private lngWnd1 As Long, lngWnd2 As Long, bolWnd1 As Boolean, bolWnd2 As Boolean, intPass As Integer
Private Sub Command1_Click()
    'Change the window title on the following line to one of the two windows'
    lngWnd1 = FindWindow(vbNullString, "Untitled - Notepad")
    bolWnd1 = True
    'Change the window title on the following line to the other of the two windows'
    lngWnd2 = FindWindow(vbNullString, "Google - Windows Internet Explorer")
    bolWnd2 = False
    Timer1.Interval = 60000
    Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
    Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
    intPass = intPass + 1
    If intPass = 2 Then
        If bolWnd1 Then
            SendMessage lngWnd1, WM_SYSCOMMAND, SC_MAXIMIZE, NIL
            BringWindowToTop lngWnd1
            SendMessage lngWnd2, WM_SYSCOMMAND, SC_MINIMIZE, NIL
            SendMessage lngWnd2, WM_SYSCOMMAND, SC_MAXIMIZE, NIL
            BringWindowToTop lngWnd2
            SendMessage lngWnd1, WM_SYSCOMMAND, SC_MINIMIZE, NIL
        End If
        bolWnd1 = Not bolWnd1
        bolWnd2 = Not bolWnd2
        intPass = 0
    End If
End Sub
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
Public Const SC_MAXIMIZE = &HF030&
Public Const SC_MINIMIZE = &HF020&
Public Const WM_SYSCOMMAND = &H112
Public Const NILL = 0&

Open in new window

transpennineAuthor Commented:
Thanks Bluedevilfan this code has been most useful and I have managed using it to do what was required thanks for the time taken to help

Regards Transpennine
David LeeCommented:
You're welcome.  Glad I could help.  Please don't forget to close the question if you're happy with the answer.
transpennineAuthor Commented:
thanks for all your help sorry for the delay
David LeeCommented:
No problem on the delay.  Please don't forget to close the question if you're satisfied with the solution.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.