Ciao a tutti, nonostante segua il forum da tanto mi sono da poco iscritto per un problemi a cui non riesco trovare soluzione.
Ho un file in Excel (2010). Ho una range B1:B50 con degli indirizzi web.
Vorrei creare una macro che:
- apra i vari url
- mi salvi le suddette pagine in .txt
- le salvi in ordine crescente (essendo tutte dello stesso sito ed avendo tutte lo stesso nome)
Io ho provato con la seguente macro:
codice:
Dim IE As Object
Option Base 0
Sub Test1()
Dim rCell As Range, myRan As Range
'
If IE Is Nothing Then Set IE = CreateObject("InternetExplorer.APPLICATION")
Set myRan = ThisWorkbook.Sheets("Foglio1").Range("B1:B50") '<<< Il foglio nel file che contiene le macro con l' elenco url
'
For Each rCell In myRan
If rCell <> "" Then
GetTabbb (rCell.Value)
'Personalizzare la prossima con Path e nome file (1) >>>
mykeys = Array("^s", "C:\Users\Luca\Desktop\prova\pippo", "{TAB}", "{TAB}", "{TAB}", "{TAB}", "{ENTER}")
DoEvents
For J = LBound(mykeys) To UBound(mykeys)
SendKeys mykeys(J), True
If J < 2 Then myWait (1) Else myWait (0.2)
Debug.Print mykeys(J)
Next J
myWait (0.5)
Debug.Print " "
Debug.Print "Next link>>>>>>>"
On Error Resume Next
'Personalizzare le prossime due con Path e nome file (2) >>>
Name "C:\Users\Luca\Desktop\prova\pippo.htm" As "C:\Users\Luca\Desktop\prova\pippo" & Format(Now(), "hh-mm-ss") & ".htm"
Name "C:\Users\Luca\Desktop\prova\pippo.txt" As "C:\Users\Luca\Desktop\prova\pippo" & Format(Now(), "yyyy-mm-dd") & ".txt"
On Error GoTo 0
End If
Next rCell
myWait (5)
Debug.Print "Kill IE"
IE.Quit
Set IE = Nothing
'
End Sub
Sub GetTabbb(myUrl)
'
With IE
ReNav:
On Error GoTo NoNav
Debug.Print ">"
myWait (0.2)
.navigate myUrl
.Visible = True
myWait (0.2)
Do While .Busy: DoEvents: Loop 'Attesa not busy
Do While .readyState <> 4: DoEvents: Loop 'Attesa documento
End With
'
'attesa addizionale
myWait (1)
Exit Sub
NoNav:
Debug.Print ("NoNav")
myWait (0.5)
On Error GoTo 0
Resume ReNav
'
End Sub
'
Sub myWait(myStab As Single)
Dim myStTiM As Single
'
myStTiM = Timer
Do 'wait myStab
DoEvents
If Timer > myStTiM + myStab Or Timer < myStTiM Then Exit Do
Loop
End Sub
Premetto che non ho moltissima dimestichezza con VBA...sono arrivato a questo vedendo un po' dal forum, perdendoci un sacco di tempo a fare prove, test...
Commetto due errori:
1) mi salva il tutto come Pagina web completa (impiegando molto tempo e salvando cartella + pagina .htm)
2) mi chiede di sovrascrivere il file pippo.
Questo perchè non riesco a dire di nominarlo con numero crescente: come potete vedere ho pensato di salvarlo con "secondi, minuti, ecc." ma senza risultati.
Dove sbaglio?