I'm using this script I compiled to get details about the documentaries that I watch. Based on the filename, I get a documentary name, I then compile a google search string, I search google, get google's response, open the correct link from it, and get the data. This used to work until a few days ago. Today, I tried running my script, and I get an error right at the very beginning, while calling the function that does the google search. This is the function:
Public Function getHTTP(ByVal url As String) As String
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", url, False
.send
getHTTP = StrConv(.responseBody, vbUnicode)
End With
End Function
"url" is compiled based on different criteria. Right now it is:
https://www.google.com/search?hl=en&source=hp&q=site:docuwiki.net+++"secrets+in+our+dna+"
The error triggers on the ".send" line. The error is:
Run-time error '-2147024891 (80070005)': Access denied.
If I then click on debug and try to run the script again (from the current point), I get another error:
Run-time error '2147467259 (80004005)': Unspecified error.
I don't think I made any changes to the system between the last time it worked and now. Haven't installed anything, no updates, nothing. I should mention that I'm on a fairly old laptop, using MSOffice 2007 under Windows 7.
Here's a minimal reproducible example. This causes the aforementioned error (that it wouldn't have a couple of weeks ago).
Public Function getHTTP(ByVal url As String) As String
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", url, False
Debug.Print url
.send
getHTTP = StrConv(.responseBody, vbUnicode)
End With
End Function
Sub testing123()
Dim a, URL1
URL1 = "https://www.google.com/search?hl=en&source=hp&q=site:docuwiki.net+bbc+""beautiful+minds+"""
a = lcase(getHTTP(URL1))
End Sub
Apparently, the problem was caused by not having opened Internet Explorer in a long time. When I tested my URLs, I only did so in Chrome. When I tried to paste the same URL in IE and access it, I got one of those cookie confirmation pages. After agreeing to the cookies and closing IE, I tested the script again and it worked like it used to.