Open a specific WebPage only one tab

Discuss the database features

Open a specific WebPage only one tab

Postby longi » Thu Mar 26, 2020 5:57 pm

Hi everyone!

Here again!
I'm trying to open a specific webpage by code, and got it successfully, but (we always have a 'but') my routine always opens a new tab.
I want to use the code in an hsqldb 2.3 multi-user database, so there are many different users, and each one can use a different web browser.
So, I need to know if a browser is already open, then if it has multiple windows or tabs, and then check each one if the web page I want is already open. If so, stop the macro, if not go to the next window or tab. In the end, if the macro can't find it, the specific web page will be opened (I'm not sure if I'm explaining correctly).
The first step I got is that I can know the browser that is running, but no more. My open office based skills are really short, but translating VBA or C ++ to basic is too much for me ... HELP!

My initial code that only opens a specific webpage in a new iexplore page:

Code: Select all   Expand viewCollapse view
Sub explor ()

    Dim URL,WshShell                                                                       
    Set WshShell = CreateObject("WScript.shell")                                            ' We start WScript.shell
    '-----------------------------------------------------------
    ' We open a specific webpage in a specific web browser
   
    URL = "https://novedades.orange.es"                                                     ' Publicity webpage
    WshShell.run "CMD /C start iexplore.exe " & URL & "",0,False                            ' It opens the web browser with the previous URL

End Sub


My code to know the web browser in use:

Code: Select all   Expand viewCollapse view
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (lpClassName,lpWindowName) As Long

Sub Comprobar

    Dim ret As Long, ArrayNavegadores(), Clas As String, Pro As String                      ' Variables

    ArrayNavegadores() = Array("IEFrame", "MozillaWindowClass", "Chrome_WidgetWin_1")       ' Array of classes of Browsers
    '----------------------------------------
    ' We loop over all classes
   
    For i= LBound(ArrayNavegadores()) To UBound(ArrayNavegadores())                         ' Cycle classes
    Clas=ArrayNavegadores(i)                                                                ' The class (i)
    ret = FindWindow(clas, NULL)                                                            ' We call the function
    '---------------------------------------
    ' We translate the name of web browserr
   
    If Clas= "IEFrame" Then                                                                 ' If the class is IEFrame   
      Pro= "Explorer"                                                                       ' It is Explorer
    End if                                                                                  ' Finish the condiction

    If Clas= "MozillaWindowClass" Then                                                      ' If the class is MozillaWindowClass
      Pro= "Mozilla"                                                                        ' It is Mozilla
    End if                                                                                  ' Finish the condiction

    If Clas= "Chrome_WidgetWin_1" Then                                                      ' If the class is Chrome_WidgetWin_1
      Pro= "Chrome"                                                                         ' It is Chrome
    End if                                                                                  ' Finish the condiction
    '----------------------------------------
    '  If ret is <>0 then it was found

    If ret <> 0 Then                                                                        ' If it is different to 0
        MsgBox "The webbrowser  " & Pro & "  is opened"                                   ' A message
    Else                                                                                    ' If it is 0
        MsgBox "The webbrowser  " & Pro & " is NOT opened"                                ' Message
    End if                                                                                  ' Finish the condiction
    Next                                                                                    ' We go to the next class

End Sub


I hope all of you would be far from the virus!

Thanks!, ;)
OpenOffice 4.1.5 on Windows 10
LibreOffice 5.1 on Windows 7
LibreOffice 6.0.1 on Windows10
longi
 
Posts: 109
Joined: Mon Jul 15, 2013 5:04 pm

Return to Base

Who is online

Users browsing this forum: No registered users and 2 guests