

Set objTempFile = objFS.OpenTextFile(strFileName, 1) ObjShell.Run "cmd /c ping " & strHostAddress & " -n 1 -w 1 > " & strFileName, 0, True StrFileName = strTempFolder & "\" & objFS.GetTempName If Dir(strTempFolder, vbDirectory) = "" Then Set objShell = CreateObject("Wscript.Shell") Set objFS = CreateObject("Scripting.FileSystemObject") I prefer it because it doesn't require any external references or DLLs.

MsgBox ("You are not connected to the Internet or there is an issue with your Internet connection.") 'code to execute Internet-required function here MsgBox ("You are connected to the Internet") 'your main function/calling function would look something like this

If R <= 4 Then IsInternetConnected = True Else IsInternetConnected = False Private Const INTERNET_CONNECTION_OFFLINE As Long = &H20įunction IsInternetConnected() As Boolean Private Const INTERNET_CONNECTION_PROXY As Long = &H4 Private Const INTERNET_CONNECTION_LAN As Long = &H2 Private Const INTERNET_CONNECTION_MODEM As Long = &H1 Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef dwflags As Long, ByVal dwReserved As Long) As Long
Office for mac internet explorer vba how to#
I found most answers here and elsewhere confusing or incomplete, so here is how to do it for idiots like me: 'paste this code in at the top of your module (it will not work elsewhere) Hopefully this should be a fairly uncommon event though

There is a slight chance that the XMLHTTP60 request could succeed and the Documents.Open one fail (or vice versa). check the URL status with the XMLHTTP60 object and then use Documents.Open to open the URL as before:.This has the disadvantage that some linked elements may be lost and you'll get a message box when the file opens Open "C:\foo.html" For Output As #hOutFile write the XMLHTTP60.ResponseText out to a text file and then call Documents.Open on that text file.(NB the HTTP status code of 200 indicates that "the request has succeeded" - see here) I'm not very familiar with VB, and VBA is ruining me in so many ways, so there's probably some easy way to do this, which is why I'm asking here.īuilding on shakalpesh's answer and the comments to it, there are (at least) two ways to get the web page into Word without parsing the XML returned by the XMLHTTP60 object. Obviously, though, this app can't tell, and because I'm not using APIs or anything, and because I am limited to using the VBA environment (I'm not even allowed MZ tools), I need to find some way to check that the internet is working before continuing with the program flow, without relying on too many references, and preferably without screenscraping for the phrase "404 Page Not Found". When a person was searching they could tell if the internet was broken and they would do their searches later. This has meant about 400 bad searches have been saved in the local folders, and inserted into the final documents. However, our Office's internet is unreliable, and has been down the last half a day. People are impressed because until a few weeks ago they did this manually by literally loading up six different search websites, searching, and then copying and pasting the results in a word document. This works fine - even though it's not quick. It saves individual search results in a number of local folders so the next time those words are searched, it grabs them locally instead of loading the website again. Wrote a small app that accesses a bunch of search websites and puts the results in a word document, which gets run a few hundred times a day.
