#

MS Access, vba: Find Parent Element

 

Der folgende vba Code sucht zu einem HTML Element das passende Parent Element bis zu einem bestimmten Typ.

 

 

In diesem Beispiel soll der vba Code solange im HTML Document nach oben wandern, bis das TABLE Element erreicht ist.

Hierzu reicht ein einfacher Aufruf wie:

Set vTR = getParent_byTag(element, "TR")

 

Code Beispiel, vba:

Suche das nächst übergeordnete Table Row Element, in welchem sich gerade das aktuelle DIV befindet.

'-< Konto_auswahl >-

Set element = getElementByTag_and_Innertext("div", "Kontokorrent")

    If Not element Is Nothing Then

    '< get parent TR >

    Dim vTR As HTMLHtmlElement

    Set vTR = getParent_byTag(element, "TR")

    If Not vTR Is Nothing Then

        '< find TR-child select >

        vTR.getElementsByTagName("SELECT")

        '</ find TR-child select >

    End If

    '</ get parent TR >

End If

'-</ Konto_auswahl >-

 

 

 

 

 

Komplette vba Code als Function zum einbetten:

Private Function getParent_byTag(ByVal element As HTMLHtmlElement, ByVal sTagname As String) As HTMLHtmlElement

    '------------< getParent_byTag() >------------

    '< get browser document >

    Dim browser As webBrowser

    Set browser = ctlBrowser.Object

    Dim hdoc As HTMLDocument

    Set hdoc = browser.Document

    '</ get browser document >

   

    Dim parent As HTMLHtmlElement

 

    '< init >

    Dim return_Element As HTMLHtmlElement

    Set return_Element = Nothing

    '</ init >

   

    '--< get Input >--

    Do Until 1 = 2

        DoEvents

        Set parent = element.parentElement

       

        If parent.tagName = sTagname Then

            '< match >

            Set return_Element = parent

            Exit Do

            '</ match >

        ElseIf parent Is Nothing Then

            '< eof >

            Set return_Element = Nothing

            Exit Do

            '</ eof >

        End If

       

        '< next >

        Set element = parent

        '</ next >

    Loop

    '--</ get Input >--

   

    '< output >

    Set getParent_byTag = return_Element

    '</ output >

    '------------</ getParent_byTag() >------------

End Functionsend-button >-

 

 

Note: To manage HTML code in Microsoft Visual Basic for applications, you must include the MSHtml Library

https://microsoft-programmierer.de/Office-365/Access/Controls/MS-Access_colon_-Webseite-mit-HTML-Document-lesen-und-HTML-Elemente-verwalten?2091

Mobile

.

0123movie.net