PDA

View Full Version : Get Msgbox in a table



Suzana
01-06-2020, 11:59 AM
Hello,

How can I get this messagebox in a table in Active sheet.

ergebnis = Chr(9) & Chr(9)
ergebnis = ergebnis & x.getElementsByTagName("th")(0).getElementsByTagName("img")(0).getAttribute("alt")
ergebnis = ergebnis & Chr(9)
ergebnis = ergebnis & x.getElementsByTagName("th")(2).getElementsByTagName("img")(0).getAttribute("alt")

ergebnis = ergebnis & Chr(13) 'Zeilenumbruch

Set y = knotenTabelle.getElementsByClassName("Alpha")

For Each y In z
ergebnis = ergebnis & y.getElementsByTagName("th")(0).innerText
If Len(y.getElementsByTagName("th")(0).innerText) > 9 Then
ergebnis = ergebnis & Chr(9) 'Ein Tab
Else
ergebnis = ergebnis & Chr(9) & Chr(9) 'Zwei Tabs
End If
ergebnis = ergebnis & y.getElementsByTagName("td")(0).innerText
ergebnis = ergebnis & Chr(9) & Chr(9) 'Zwei Tabs
ergebnis = ergebnis & y.getElementsByTagName("td")(1).innerText
ergebnis = ergebnis & Chr(13) 'Zeilenumbruch
Next z
End If
MsgBox ergebnis
End Sub

p45cal
01-06-2020, 02:27 PM
try, instead of MsgBox ergebnis this:
Set Destn = Range("L3") 'or wherever you choose top left to be
xx = Split(ergebnis, Chr(13))
For zz = 0 To UBound(xx)
p = Split(xx(zz), Chr(9))
Destn.Offset(zz).Resize(, UBound(p) + 1).Value = p
Next zz

Suzana
01-06-2020, 04:18 PM
Something is wrong with it.
Can you please have a look?

Dim xx
Dim p
Dim zz As Long

Destn.Offset(zz).Resize(, UBound(p) + 1).Value = p --> 1004 application-defined or object-defined

p45cal
01-06-2020, 04:39 PM
I've no idea what ends up being in ergebnis so it's difficult to reproduce your error (I can't).
What is p when you get the error? Is it an array?
You can test this:
Instead of:
Destn.Offset(zz).Resize(, UBound(p) + 1).Value = p
try:
If UBound(p) > -1 Then Destn.Offset(zz).Resize(, UBound(p) + 1).Value = p

Perhaps attach a workbook where you've managed to get a typical value in ergebnis?

Suzana
01-07-2020, 06:26 AM
Hello p45cal,

thanks for your help. Ergebnis looks like the example.jpg

So prefer something like this:

Range("H2") = x.getElementsByTagName("th")(0).getElementsByTagName("img")(0).getAttribute ("alt")
Range("J2" = x.getElementsByTagName("th")(2).getElementsByTagName("img")(0).getAttribute ("alt")

Set y = knotenTabelle.getElementsByClassName("Alpha")
For Each y In z
ergebnis = ergebnis & y.getElementsByTagName("th")(0).innerText
If Len(y.getElementsByTagName("th")(0).innerText) > 9 Then
ergebnis = ergebnis & Chr(9) 'Ein Tab
Else
ergebnis = ergebnis & Chr(9) & Chr(9) 'Zwei Tabs
End If
ergebnis = ergebnis & y.getElementsByTagName("td")(0).innerText
ergebnis = ergebnis & Chr(9) & Chr(9) 'Zwei Tabs
ergebnis = ergebnis & y.getElementsByTagName("td")(1).innerText
ergebnis = ergebnis & Chr(13) 'Zeilenumbruch
Next z
End If
MsgBox ergebnis
End Sub

But I have some problems with the loop.

p45cal
01-07-2020, 07:21 AM
There's just not enough information to offer a solution for this one. If ergebnis contains what's in the picture, it's not very useful is it?
We need to know what x is - I realise it's likely to be an html document, or part of one, but these tiny snippets of code are not enough.
Are you web scraping? Is the site you're scraping publicly available? If so, attach a workbook with more code and urls.