Moderatori: Anthony47, Flash30005
Sub findStr()
Dim IFound, I As Long, myF As String, myPath As String, myType As String, LastA As Long
'
myPath = Range("B1") & "\"
myType = Range("B2") & "*"
'
LastA = Cells(Rows.Count, 1).End(xlUp).Row
'
If Mid(myPath, 2, 1) = ":" Then ChDrive Left(myPath, 1)
myF = Dir(myPath & "*." & myType)
Application.EnableEvents = False
With ThisWorkbook.ActiveSheet
While myF <> ""
Application.ScreenUpdating = True: DoEvents
.Range("B4") = .Range("B4") + 1
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks.Open myPath & myF
Application.DisplayAlerts = True
For I = 8 To LastA
mylook = .Cells(I, 1).Value
Set IFound = ActiveSheet.Cells.Find(what:=mylook, LookIn:=xlValues, LookAt:=xlPart)
If Not IFound Is Nothing Then
.Cells(Rows.Count, 4).End(xlUp).Offset(1, 0) = myPath & myF
.Range("B5") = .Range("B5") + 1
Exit For
End If
Next I
ActiveWorkbook.Close False
myF = Dir
Wend
End With
Application.EnableEvents = True
MsgBox ("Completato")
End Sub
Eh, lo sapevo...Ho provato la Macro, mi ha fatto capire diverse cose sul VB, ma non è quello che mi serve
Sub Main()
Dim Cioppa, I As Long, lastA As Long
'
Sheets("Foglio1").Select '<<< Il foglio con gli Url
'
lastA = Cells(Rows.Count, 1).End(xlUp).Row
Range("B2").Resize(lastA + 10, 250).ClearContents
For I = 2 To lastA
Cells(I, 1).Select: DoEvents
Cioppa = CercaWord(Cells(I, 1), Sheets("Foglio2").Range("A2:A100"))
Cells(I, 2).Resize(1, UBound(Cioppa)).Value = Cioppa
Next I
MsgBox ("Completato...")
End Sub
Function CercaWord(ByVal myURL As String, ByRef myWD As Range) As Variant
Dim HTDoc As Object, htmTxt As String
Dim I As Long, K As Long, myC As Range, oArr()
'
Set HTDoc = CreateObject("HTMLfile") 'late binding alla html obj lib
'0
On Error Resume Next
With CreateObject("WINHTTP.WinHTTPRequest.5.1")
.Open "GET", myURL, False
.send
CallByName HTDoc, "Write", VbMethod, .responsetext
End With
On Error GoTo 0
htmTxt = HTDoc.getelementsbytagname("body")(0).innertext
ReDim oArr(1 To myWD.Cells.Count)
For Each myC In myWD
If myC.Value <> "" Then
If InStr(1, htmTxt, myC.Value, vbTextCompare) > 0 Then
K = K + 1
oArr(K) = myC.Value
End If
End If
Next myC
If K = 0 Then K = 1
ReDim Preserve oArr(1 To K)
CercaWord = oArr
Set HTDoc = Nothing
End Function
htmTxt = HTDoc.getelementsbytagname("body")(0).innerHTML ' .innertext
Con riferimento (ad esempio) al sorgente di http://www.centroesteticomaridea.it puoi specificare a quali informazioni fai riferimento?Volevo chiedervi se si può inserire in questa macro la possibilità di copiare il title, meta description e meta keywords nelle colonne adiacenti
Function CercaWord(ByVal myURL As String, ByRef myWD As Range) As Variant
Dim HTDoc As Object, htmTxt As String
Dim I As Long, K As Long, myC As Range, oArr()
'
Set HTDoc = CreateObject("HTMLfile") 'late binding alla html obj lib
'0
On Error Resume Next
With CreateObject("WINHTTP.WinHTTPRequest.5.1")
.Open "GET", myURL, False
.send
CallByName HTDoc, "Write", VbMethod, .responsetext
End With
On Error GoTo 0
htmTxt = HTDoc.getElementsByTagName("body")(0).innerText
'htmTxt = HTDoc.getElementsByTagName("body")(0).innerHTML
ReDim oArr(1 To myWD.Cells.Count + 3)
K = 3
For Each myC In myWD
If myC.Value <> "" Then
If InStr(1, htmTxt, myC.Value, vbTextCompare) > 0 Then
K = K + 1
oArr(K) = myC.Value
End If
End If
Next myC
oArr(1) = HTDoc.getElementsByTagName("title")(0).innerText
Dim mColl As Object, mItm As Object
Set mColl = HTDoc.getElementsByTagName("meta")
For Each mItm In mColl
Debug.Print mItm.outerHTML
If InStr(1, mItm.outerHTML, "=keyword", vbTextCompare) > 0 Then
oArr(3) = mItm.getAttribute("content")
ElseIf InStr(1, mItm.outerHTML, "=description", vbTextCompare) > 0 Then
oArr(2) = mItm.getAttribute("content")
End If
Next mItm
If K = 0 Then K = 1
ReDim Preserve oArr(1 To K)
CercaWord = oArr
Set HTDoc = Nothing
End Function
Torna a Applicazioni Office Windows
Inserire add.in nella barra di avvio veloce in excel 2003 Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 4 |
Excel: problema con date se devo unirle a testi Autore: valle1975 |
Forum: Applicazioni Office Windows Risposte: 5 |
confrontare e evidenziare 2 fogli excel Autore: niccia |
Forum: Applicazioni Office Windows Risposte: 7 |
Visitano il forum: Nessuno e 11 ospiti