Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to code this macro?? I would like to check whether there is any text on cell

ID: 3570262 • Letter: H

Question

How to code this macro??

I would like to check whether there is any text on cell A1 or not, so I can determine whether the web page is inserted or not.If there is no text in cell A1, then repeat this process until it is loaded successfully, and set maximum number of trial at 7 times

Does anyone have any suggestions on how to code it in macro??
Thanks in advance for any suggestions!

Sub Web_Page()
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.cnn.com", Destination _
        :=Range("A1"))
        .name = "Temp"
        .FieldNames = True
        .RowNumbers = False
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub

Explanation / Answer

Hi

Try something like:

'=========>>
Sub Web_Page()
Dim i As Long

For i = 1 To 7
On Error GoTo ErrHandler.
If Range("A1").Value <> "" Then Exit Sub
With ActiveSheet.QueryTables.Add(Connection:=
"URL;http://www.cnn.com", _
Destination:=Range("A1"))
.Name = "Temp"
.FieldNames = True
.RowNumbers = False
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Retry:
Next i
Exit Sub
ErrHandler:
Select Case Err.Number
Case Is <> "1004"
MsgBox "Error number - " & Err.Number & " - " & Err.Description
Case Else
Application.Wait Now + TimeValue("00:00:05")
Resume Retry
End Select
End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote