Excel VBA – Verificar conexão com a Internet
ago.29, 2008 in
Desenvolvimento, Excel, Microsoft Office, VBA
Método simples para verificar se o computador está ou não conectado a Internet por VBA.
Copie e cole o seguinte código em um módulo VBA:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" _ (ByRef lpdwFlags As Long, _ ByVal lpszConnectionName As String, _ ByVal dwNameLen As Integer, _ ByVal dwReserved As Long) _ As Long Dim sConnType As String * 255 Sub TesteConexaoInternet() Dim Ret As Long Ret = InternetGetConnectedStateEx(Ret, sConnType, 254, 0) If Ret = 1 Then MsgBox "Você está conectado a Internet via " & sConnType, vbInformation Else MsgBox "Você não está conectado a Internet", vbInformation End If End Sub |
A chamada retorna uma mensagem que avisa se existe conexão com a Internet e através de qual conexão ela é feita.
Abraços
Tomás

22 Convidados
1 Bot
agosto 29th, 2008 at 16:46
Espetacular.
Eu estava justamente precisando disto.
Muito obrigado !!!
junho 30th, 2010 at 13:15
Prof. Tomás,
caso eu esteja em rede local, vai acusar que estou conectado.
Tem algum VBA pra validar a conexão com um site, ou seja, validar que o computador esta realmente ligado à internet?
Objetivo, caso esteja conectado mandar um e-mail.
Agradeço qualquer retorno.
Atenciosamente,
Rogério dos Santos Ferreira
julho 1st, 2010 at 11:11
Rogério,
Segue um uso mais completo da função acima:
http://vbnet.mvps.org/index.html?code/network/internetgetconnectedstate.htm
Abraços
Tomás