AW: eigener Ansatz
25.07.2024 15:27:03
Christian
Also habe jetzt folgendes gemacht:
Das ursprüngliche Makro
Public Sub Makro2(sh As String)
Dim objIE As Object
Dim objLinks As Object
Dim objLink As Object
Dim lngCount As Long
Dim lloRow As Long
Dim lshTab2 As Worksheet
Set lshTab2 = Sheets(sh)
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = False
For lloRow = 1 To lshTab2.Cells(lshTab2.Rows.Count, 1).End(xlUp).Row
.Navigate lshTab2.Range("A" & lloRow).Text
Do While .Busy Or .readyState > 4
DoEvents
Loop
' Check if the page loaded successfully
If .LocationURL > "about:blank" Then
Set objLinks = .document.Links
For Each objLink In objLinks
lngCount = lngCount + 1
lshTab2.Cells(lngCount, 2) = objLink.href
lshTab2.Cells(lngCount, 3) = "'" & objLink.outerText
Next objLink
End If
Application.Wait (Now + TimeValue("0:00:05"))
Next lloRow
.Quit
End With
Set objIE = Nothing
Set lshTab2 = Nothing
End Sub
erstmal habe ich gesagt, dass die Sachen in Spalte C und D eingetragen werden sollen, damit Spalte B für die X frei wird.
Public Sub Makro2(sh As String)
Dim objIE As Object
Dim objLinks As Object
Dim objLink As Object
Dim lngCount As Long
Dim lloRow As Long
Dim lshTab2 As Worksheet
Set lshTab2 = Sheets(sh)
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = False
For lloRow = 1 To lshTab2.Cells(lshTab2.Rows.Count, 1).End(xlUp).Row
.Navigate lshTab2.Range("A" & lloRow).Text
Do While .Busy Or .readyState > 4
DoEvents
Loop
' Check if the page loaded successfully
If .LocationURL > "about:blank" Then
Set objLinks = .document.Links
For Each objLink In objLinks
lngCount = lngCount + 1
lshTab2.Cells(lngCount, 3) = objLink.href
lshTab2.Cells(lngCount, 4) = "'" & objLink.outerText
Next objLink
End If
Application.Wait (Now + TimeValue("0:00:05"))
Next lloRow
.Quit
End With
Set objIE = Nothing
Set lshTab2 = Nothing
End Sub
dann habe ich gesagt, dass in jede abgearbeitete Zeile ein X geschrieben werden soll
Public Sub Makro2(sh As String)
Dim objIE As Object
Dim objLinks As Object
Dim objLink As Object
Dim lngCount As Long
Dim lloRow As Long
Dim lshTab2 As Worksheet
Set lshTab2 = Sheets(sh)
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = False
For lloRow = 1 To lshTab2.Cells(lshTab2.Rows.Count, 1).End(xlUp).Row
.Navigate lshTab2.Range("A" & lloRow).Text
Do While .Busy Or .readyState > 4
DoEvents
Loop
' Check if the page loaded successfully
If .LocationURL > "about:blank" Then
Set objLinks = .document.Links
For Each objLink In objLinks
lngCount = lngCount + 1
lshTab2.Cells(lngCount, 3) = objLink.href
lshTab2.Cells(lngCount, 4) = "'" & objLink.outerText
Next objLink
End If
lshTab2.Cells(lloRow, 2) = "X"
Application.Wait (Now + TimeValue("0:00:05"))
Next lloRow
.Quit
End With
Set objIE = Nothing
Set lshTab2 = Nothing
End Sub
und im 3. Schritt nur Links abarbeiten, neben denen kein X steht
Public Sub Makro2(sh As String)
Dim objIE As Object
Dim objLinks As Object
Dim objLink As Object
Dim lngCount As Long
Dim lloRow As Long
Dim lshTab2 As Worksheet
Set lshTab2 = Sheets(sh)
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = False
For lloRow = 1 To lshTab2.Cells(lshTab2.Rows.Count, 1).End(xlUp).Row
' Prüfen, ob in Spalte B bereits ein "X" steht
If lshTab2.Cells(lloRow, 2).Text > "X" Then
.Navigate lshTab2.Range("A" & lloRow).Text
Do While .Busy Or .readyState > 4
DoEvents
Loop
' Check if the page loaded successfully
If .LocationURL > "about:blank" Then
Set objLinks = .document.Links
For Each objLink In objLinks
lngCount = lngCount + 1
lshTab2.Cells(lngCount, 3) = objLink.href
lshTab2.Cells(lngCount, 4) = "'" & objLink.outerText
Next objLink
End If
lshTab2.Cells(lloRow, 2) = "X"
Application.Wait (Now + TimeValue("0:00:05"))
End If
Next lloRow
.Quit
End With
Set objIE = Nothing
Set lshTab2 = Nothing
End Sub
dann noch die Prüfung, ob alle Einträge in einer Tabelle bereits ein X haben
Public Sub Makro2(sh As String)
Dim objIE As Object
Dim objLinks As Object
Dim objLink As Object
Dim lngCount As Long
Dim lloRow As Long
Dim lshTab2 As Worksheet
Dim allX As Boolean
Set lshTab2 = Sheets(sh)
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = False
' Überprüfen, ob alle Zellen in Spalte B ein "X" enthalten
allX = True
For lloRow = 1 To lshTab2.Cells(lshTab2.Rows.Count, 1).End(xlUp).Row
If lshTab2.Cells(lloRow, 2).Text > "X" Then
allX = False
Exit For
End If
Next lloRow
' Wenn nicht alle Zellen in Spalte B ein "X" enthalten, das Makro ausführen
If Not allX Then
For lloRow = 1 To lshTab2.Cells(lshTab2.Rows.Count, 1).End(xlUp).Row
' Prüfen, ob in Spalte B bereits ein "X" steht
If lshTab2.Cells(lloRow, 2).Text > "X" Then
.Navigate lshTab2.Range("A" & lloRow).Text
Do While .Busy Or .readyState > 4
DoEvents
Loop
' Check if the page loaded successfully
If .LocationURL > "about:blank" Then
Set objLinks = .document.Links
For Each objLink In objLinks
lngCount = lngCount + 1
lshTab2.Cells(lngCount, 3) = objLink.href ' Link in Spalte C
lshTab2.Cells(lngCount, 4) = "'" & objLink.outerText ' Linktext in Spalte D
Next objLink
End If
' Schreib "X" in Spalte B neben den abgearbeiteten Link
lshTab2.Cells(lloRow, 2) = "X"
Application.Wait (Now + TimeValue("0:00:05"))
End If
Next lloRow
End If
.Quit
End With
Set objIE = Nothing
Set lshTab2 = Nothing
End Sub
das Hauptmakro
Public Sub Start()
Call Makro2("Tabelle1")
Call Makro2("Tabelle2")
Call Makro2("Tabelle3")
Call Makro2("Tabelle4")
Call Makro2("Tabelle5")
Call Makro2("Tabelle6")
Call Makro2("Tabelle7")
Call Makro2("Tabelle8")
Call Makro2("Tabelle9")
Call Makro2("Tabelle10")
End Sub
habe ich unverändert gelassen.
Was meint ihr dazu? bislang noch ungetestet