Hi all, please can anyone help with this query.
The following code copies text from my webpage and will paste it into my spreadsheet.
My webpage has absolutely nothing on it except a simple text like "DR-V1.4" or similar.
No tables or visible fields of data - just simply the writing made up of 7 or 8 characters.
Running the code on my private machine works great - it copies the webpage text with no issues.
Running the code on my work laptop causes all sorts of issues - when it tries to look at my site,
a login webpage appears first asking for my log in details etc, then the code copies text from that
login page into the spreadsheet writing over formula's etc.
Hands up, I did not write the following code and like many others, try to learn with the help of others.
My question is in 2 parts or has 2 ways of checking for errors which I am struggling with.
Check 1. If a company login page appears first, the code will stop.
Check 2. If copied info is more than plain text of 7 or 8 characters, the code will stop.
Here is the code.
Sub Test()
Application.Calculation = xlCalculationManual
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
On Error Resume Next
With Worksheets("Quick Search").QueryTables.Add(Connection:="URL;http://mypages.co.uk/dr", Destination:=Worksheets("Quick Search").Range("J1"))
.Name = "Info"
.FieldNames = False
.WebSelectionType = xlEntirePage
.RefreshStyle = xlOverwriteCells
.Refresh BackgroundQuery:=False
End With
Dim i As Integer
With Worksheets("Quick Search")
For i = .QueryTables.Count To 1 Step -1
.QueryTables(i).Delete
Next
End With
Dim myName As Name
For Each myName In Worksheets("Quick Search").Names
If myName.NameLocal <> "*Info*" Then
myName.Delete
End If
Next
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Application.Calculation = xlCalculationAutomatic
Set myName = Nothing
End Sub
Any help is much appreciated.
Bookmarks