2016-09-29 4 views
-1

Ich habe ein VBA-Skript, das eine Zelle überprüft, ob es „URL“ und gibt die Ergebnisse in Zeile 2, Spalte 4 & 5.Alter VBA-Code auf alle Zeilen in der Spalte anwenden, nicht nur bestimmte Zeile

I benannt ist Ich möchte es so ändern, dass es alle Zellen in Spalte C überprüft und es in Spalte D & E relativ zu der gerade überprüften Zelle exportiert.

Wenn es möglich ist, eine zeitgesteuerte Verzögerung zwischen jeder Zellenausführung hinzuzufügen, wäre das großartig.

IE

auf Spalte C ausführen, Reihe 2, Drucker 1 Sekunde auf Spalte C Execute Warten , Reihe 3, Druckergebnisse Warten Sie 1 Sekunde

Etc.

Private Changing As Boolean 

Private Sub RedirectChecker(ByVal url As String) 
Dim sh As Worksheet 
Set sh = ActiveSheet 

Dim http As New WinHttp.WinHttpRequest 
http.Option(WinHttpRequestOption_UserAgentString) = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)" 
http.Option(WinHttpRequestOption_EnableRedirects) = False 

'' Clear existing info 
sh.Cells(2, 4).Formula = "" 
sh.Cells(2, 5).Formula = "" 
DoEvents 

'' Add protocol if missing 
If (InStr(url, "://") = 0) Then 
    url = "http://" & url 
End If 

'' Launch the HTTP request 
http.Open "GET", url 
If Err.Number <> 0 Then 
    '' Handle URL formatting errors 
    sh.Cells(2, 4).Formula = Trim(Err.Description) 
    Exit Sub 
End If 
http.Send 
If Err.Number <> 0 Then 
    '' Handle HTTP errors 
    sh.Cells(2, 4).Formula = Trim(Err.Description) 
    Exit Sub 
End If 
'' Show HTTP response info 
sh.Cells(2, 4).Formula = http.Status & " " & http.StatusText 
sh.Cells(2, 5).Formula = http.GetResponseHeader("Location") 
End Sub 


Private Sub Worksheet_Change(ByVal Target As Range) 
If Changing Then Exit Sub 
Changing = True 
Dim Name As String 
On Error Resume Next 
Name = Target.Name.Name 
If Name = "URL" Then 
    RedirectChecker Target.Value 
End If 
On Error GoTo 0 
Changing = False 
End Sub 
+0

Könnten Sie ein Beispiel dafür, was Sie hier suchen. Ihre Frage scheint etwas verwirrend. – Animesh

+0

Arbeit wie folgt: https://s14.postimg.org/ub4tg8jy9/work_like_this.jpg Nicht so: https://s14.postimg.org/7xx2tfj0h/not_that.jpg – alex2k5

Antwort

0

Sie haben können der Code warten auf eine zweite wie folgt aus:

Application.Wait (jetzt + ZeitWert ("00.00.01"))

Sie müssen das nur irgendwo in Ihre Schleife integrieren, beantwortet das Ihre Frage? ps versuchen google: Excel-VBA-1 Sekunde warten

Code genommen von Achaibou Karim Beitrag: https://stackoverflow.com/a/23984113/6868389

Verwandte Themen