Rem Version 2 - 17-12-15
Rem Ekstra referencer er sat: Microsoft Internet Controls & Microsoft HTML Object Library
Const startRække = 2 'kan evt. justeres
Const startKolonne = 2 '- " -
Dim antalKolonner As Integer, antalRækker As Integer, ræk As Integer, ytLink As String
Dim Tekst As String, vTekst As String, tabel As Variant, x As Long, tæller As Long
Sub HentFraYT()
antalKolonner = ActiveCell.SpecialCells(xlLastCell).Column
antalRækker = ActiveCell.SpecialCells(xlLastCell).Row
For ræk = startRække To antalRækker
ytLink = Range("A" & ræk)
tæller = hentTællerFraYouTube(ytLink)
indsætIkolonne tæller, ræk
Next ræk
ActiveSheet.Columns.AutoFit
End Sub
Private Sub indsætIkolonne(tæller, ræk)
Dim kol As Integer, mDåR As String
mDåR = Format(Now, "mmm-yy")
For kol = 2 To antalKolonner
If Format(Cells(1, kol), "mmm-yy") = mDåR Then
Cells(ræk, kol) = tæller
Exit Sub
End If
Next kol
End Sub
Private Function hentTællerFraYouTube(ytKode)
Dim ie As InternetExplorer
Dim html As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = False
ie.Navigate "
https://www.youtube.com/watch?v=" & ytKode
Do While ie.ReadyState <> READYSTATE_COMPLETE
Application.StatusBar = "Vent venligst..."
DoEvents
Loop
Set html = ie.Document
ie.Visible = False
Tekst = html.DocumentElement.innerHTML
x = InStr(Tekst, "view-count")
vTekst = Mid(Tekst, x + 12)
tabel = Split(vTekst, "<")
hentTællerFraYouTube = tabel(0)
Set ie = Nothing
Application.StatusBar = ""
End Function
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address = "$A$1" Then
Cancel = True
HentFraYT
End If
End Sub