IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

VBA Excel - WEB


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Invité
    Invité(e)
    Par défaut VBA Excel - WEB
    Bonjour,

    Je souhaiterais savoir comment récupérer par une macro sur Excel, l'url de la page du navigateur ouvert et copier cette page sur une feuille Excel afin de retraiter les données du tableau qui y figure.
    Mais sans pour cela connaitre quel navigateur est ouvert.
    Et quelle librairie est à rajouter dans les préférences ?

    j'ai trouvé ceci, mais ca ne fonctionne pas

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    '~~> Set a reference to Microsoft Internet Controls
     
    '~~> The GetWindow function retrieves the handle of a window that has
    '~~> the specified relationship (Z order or owner) to the specified window.
    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
    ByVal wCmd As Long) As Long
     
    '~~> The GetForegroundWindow function returns the handle of the foreground
    '~~> window (the window with which the user is currently working).
    Private Declare Function GetForegroundWindow Lib "user32" () As Long
     
    Sub GetURL()
        Dim sw As SHDocVw.ShellWindows
        Dim objIE As SHDocVw.InternetExplorer
        Dim topHwnd As Long, nextHwnd As Long
        Dim sURL As String, hwnds As String
     
        Set sw = New SHDocVw.ShellWindows
     
        '~~> Check the number of IE Windows Opened
        '~~> If more than 1
        hwnds = "|"
        If sw.Count > 1 Then
            '~~> Create a string of hwnds of all IE windows
            For Each objIE In sw
                hwnds = hwnds & objIE.hwnd & "|"
            Next
     
            '~~> Get handle of handle of the foreground window
            nextHwnd = GetForegroundWindow
     
            '~~> Check for the 1st IE window after foreground window
            Do While nextHwnd > 0
     
                nextHwnd = GetWindow(nextHwnd, 2&)
                If InStr(hwnds, "|" & nextHwnd & "|") > 0 Then
                    topHwnd = nextHwnd
                    Exit Do
                End If
            Loop
     
            '~~> Get the URL from the relevant IE window
            For Each objIE In sw
                If objIE.hwnd = topHwnd Then
                    sURL = objIE.LocationURL
                    Exit For
                End If
            Next
        '~~> If only 1 was found
        Else
            For Each objIE In sw
                sURL = objIE.LocationURL
            Next
        End If
     
        MsgBox (sURL)
     
        Debug.Print sURL
     
        Set sw = Nothing: Set objIE = Nothing
    End Sub
    Vous en remerciant par avance.

    Cordialement.
    Dernière modification par Invité ; 17/06/2022 à 09h53.

  2. #2
    barpasc
    Invité(e)
    Par défaut
    cherchez à savoir ce quel navigateur l'utilisateur a ouvert et référencer ce navigateur en vba est un peu compliqué... python, c sharp.... ou sinon forcer l'utilisateur à ouvrir un navigateur spécifique (par exemple le navigateur par défault) et référencer ce navigateur dans excel

  3. #3
    Invité
    Invité(e)
    Par défaut
    Bonjour Barpasc,

    Ils utilisent essentiellement Chrome.

    Mais certains (minorité) peuvent utiliser Microsoft Edge.

Discussions similaires

  1. services web xml avec vba excel
    Par naim8622 dans le forum VB.NET
    Réponses: 0
    Dernier message: 15/01/2009, 16h21
  2. appel de web services avec les vba excel qui manipule les xsl.
    Par naim8622 dans le forum Services Web
    Réponses: 0
    Dernier message: 13/01/2009, 09h57
  3. [VBA EXCEL] Importation données Web
    Par pwrollez dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 23/02/2007, 08h27
  4. VBA Excel vs web - mauvais rafraichissement des controles
    Par Kraaan dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 06/02/2007, 11h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo