Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1596to1600
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

html mit vba verändern

html mit vba verändern
10.12.2017 16:09:34
bignnnboss@gmail.com
Mein code bis jetzt:

Sub c()
Dim IEApp As Object
Dim IEDocument As Object
Dim a As Long
On Error GoTo err_clear
Set IEApp = CreateObject("InternetExplorer.Application")
IEApp.Visible = True
IEApp.navigate "homepage1"
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEApp.Busy = False
Set IEDocument = IEApp.Document
Do: Loop Until IEDocument.readyState = "complete"
Do: Loop Until IEApp.Busy = False
IEDocument.getElementbyId("usernameLogin").Value = "Username"
IEDocument.getElementbyId("passwordLogin").Value = "password"
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("loginSubmit").Click
Do: Loop Until IEDocument.readyState = "complete"
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEApp.Busy = False
IEApp.navigate "homepage2"
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEApp.navigate "homepage3"
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("sendall").Click
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("continue").Click
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("system").Value = 432
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("position").Value = 6
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("continue").Click
Do: Loop Until IEDocument.readyState = "complete"
Do: Loop Until IEApp.Busy = False
IEDocument.getElementbyId("button3").click
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
Um diesen Button3 geht es. Mit Click passiert Garnichts...
IEDocument.getElementbyId("allresources").Click
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("start").Click
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
err_clear:
If Err  0 Then
Err.Clear
Resume Next
End If
Set IEDocument = Nothing
Set IEApp = Nothing
End Sub

danke für eure hilfe. Ps: ich bin absoluter Neuling im bezug auf Homepage makros, also bitte verzeiht mir, falls einiges nicht den guten Techniken entspricht.

3
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: html mit vba verändern
10.12.2017 16:12:12
bignnnboss@gmail.com
Hallo Zusammen,
ich würde gerne durch VBA eine Homepage steuern.
vor allem mit getelementbyid ist das ja relativ leicht.
Aber:
Aber um den makro abzuschließen, muss ich eine Auswahl treffen, die ich leider nicht mit hilfe von GetElementbyId hinbekommen.
Hier der Code vor dem Anklicken
" id="missionButton3" onclick='setSelected(3);
updateMission(
"Transport",
"Transportiere deine Rohstoffe zu anderen Planeten.",
"on",
3 );' href="javascript:void(0);">
Transport"
und nach dem Anklicken
" class="selected" id="missionButton3" onclick='setSelected(3);
updateMission(
"Transport",
"Transportiere deine Rohstoffe zu anderen Planeten.",
"on",
3 );' href="javascript:void(0);">
Transport
"
Es wird nur das class="selected" hinzugefügt, leider kann ich das mit meinem VBA Skills nicht umsetzen:(
Mein code bis jetzt:

Sub c()
Dim IEApp As Object
Dim IEDocument As Object
Dim a As Long
On Error GoTo err_clear
Set IEApp = CreateObject("InternetExplorer.Application")
IEApp.Visible = True
IEApp.navigate "homepage1"
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEApp.Busy = False
Set IEDocument = IEApp.Document
Do: Loop Until IEDocument.readyState = "complete"
Do: Loop Until IEApp.Busy = False
IEDocument.getElementbyId("usernameLogin").Value = "Username"
IEDocument.getElementbyId("passwordLogin").Value = "password"
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("loginSubmit").Click
Do: Loop Until IEDocument.readyState = "complete"
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEApp.Busy = False
IEApp.navigate "homepage2"
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEApp.navigate "homepage3"
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("sendall").Click
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("continue").Click
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("system").Value = 432
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("position").Value = 6
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("continue").Click
Do: Loop Until IEDocument.readyState = "complete"
Do: Loop Until IEApp.Busy = False
IEDocument.getElementbyId("button3").click
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
Um diesen Button3 geht es. Mit Click passiert Garnichts...
IEDocument.getElementbyId("allresources").Click
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
IEDocument.getElementbyId("start").Click
Do: Loop Until IEApp.Busy = False
Do: Loop Until IEDocument.readyState = "complete"
err_clear:
If Err  0 Then
Err.Clear
Resume Next
End If
Set IEDocument = Nothing
Set IEApp = Nothing
End Sub

danke für eure hilfe. Ps: ich bin absoluter Neuling im bezug auf Homepage makros, also bitte verzeiht mir, falls einiges nicht den guten Techniken entspricht.
Anzeige
AW: html mit vba verändern
10.12.2017 16:33:44
ChrisL
Hi
Schuss ins Blaue, Dropdown Listenauswahl:
IEDocument.forms("unbekannt").Item("missionButton3").Value = "unbekannt"
cu
Chris
AW: html mit vba verändern
11.12.2017 00:28:18
Zwenn
Hallo bignnnboss,
ich bin nicht sicher, was Du am Ende erreichen willst, ich bin mir aber ziemlich sicher, dass es anders einfacher geht. Aber mal ein paar grundsätzliche Anmerkungen:
  • Die folgenden beiden Zeilen machen exakt das gleiche. Sie warten, bis die aktuell zu ladende Siete vollständig geladen wurde:
    
    Do: Loop Until IEApp.Busy = False
    Do: Loop Until IEDocument.readyState = "complete"
    

    Statt "complete" kannst Du auch 4 schreiben. Eine dieser Zeilen brauchst Du nur, wenn Du im Browser eine neue Seite laden lässt. Das ist in der Regel mit browser.navigate url der Fall. Bei Dir werden vermutlich auch neue Seiten durch .click geladen. Aber alle anderen Loop-Anweisungen kannst Du erstazlos streichen

  • Bei diesem Codeabschnitt, rufst Du erst eine Seite auf und direkt danach eine andere. Wozu dient der erste Aufruf? Du machst doch gar nix mit der Seite:
    
    IEApp.navigate "homepage2"
    Do: Loop Until IEApp.Busy = False
    IEApp.navigate "homepage3"
    Do: Loop Until IEApp.Busy = False
    

  • Mit
    
    Set IEDocument = IEApp.Document
    

    übergibst Du das gesamte Dokument des Browsers an eine Variable. Anschließend arbeitest Du ausschließlich mit dieser Variable. Das ist sinnfrei. Man verwendet die Set-Befehle in diesem Zusammenhang, um Teile des Browser-Dokuments mit den getElementsBy-Befehlen in einer Variable zu speichern, um anschließend mit einer Unterstruktur arbeiten zu können.

  • Da Du nicht geschrieben hast, um welche Seite es sich handelt, hier einmal Dein Quelltext, bereinigt um die überflüssigen Loop-Anweisungen und ohne die überflüssige IEDocument-Variable:
    
    Sub c()
    Dim IEApp As Object
    Dim a As Long
    On Error GoTo err_clear
    Set IEApp = CreateObject("InternetExplorer.Application")
    IEApp.Visible = True
    IEApp.navigate "homepage1"
    Do: Loop Until IEApp.Busy = False
    IEApp.Document.getElementbyId("usernameLogin").Value = "Username"
    IEApp.Document.getElementbyId("passwordLogin").Value = "password"
    IEApp.Document.getElementbyId("loginSubmit").Click
    Do: Loop Until IEApp.Busy = False
    IEApp.navigate "homepage2"
    Do: Loop Until IEApp.Busy = False
    IEApp.navigate "homepage3"
    Do: Loop Until IEApp.Busy = False
    IEApp.Document.getElementbyId("sendall").Click
    Do: Loop Until IEApp.Busy = False
    IEApp.Document.getElementbyId("continue").Click
    Do: Loop Until IEApp.Busy = False
    IEApp.Document.getElementbyId("system").Value = 432
    IEApp.Document.getElementbyId("position").Value = 6
    IEApp.Document.getElementbyId("continue").Click
    Do: Loop Until IEApp.Busy = False
    IEApp.Document.getElementbyId("button3").Click
    Do: Loop Until IEApp.Busy = False
    'Um diesen Button3 geht es. Mit Click passiert Garnichts...
    IEApp.Document.getElementbyId("allresources").Click
    Do: Loop Until IEApp.Busy = False
    IEApp.Document.getElementbyId("start").Click
    Do: Loop Until IEApp.Busy = False
    err_clear:
    If Err  0 Then
    Err.Clear
    Resume Next
    End If
    Set IEApp = Nothing
    End Sub
    
    Das Einloggen musst Du machen, wie Du es schon umgesetzt hast. Aber danach schau Dir mal die URL der Seite an, auf die Du eigentlich willst. Es ist gut möglich, dass die ganzen Werte, die Du über das Makro in die Formulare einträgst, als Parameter da drin stehen. Dann kannst Du Dir das ganze Brimborium sparen und direkt die Seite aufrufen, indem Du Dir die URL einfach entsprechend zusammensetzt.
    Falls das nicht geht, kann man Dir vermutlich nur helfen, wenn der ganze Quelltext der Seite bekannt ist, auf der es zum Fehlverhalten kommt. Mit kleinen Codeschnipseln kann man meistens nicht viel anfangen. Dazu habe ich hier mal was geschrieben:
    https://www.herber.de/cgi-bin/callthread.pl?index=1593619
    Viele Grüße,
    Zwenn
    Anzeige

    Links zu Excel-Dialogen

    Beliebteste Forumthreads (12 Monate)

    Anzeige

    Beliebteste Forumthreads (12 Monate)

    Anzeige
    Anzeige
    Anzeige