Results 1 to 4 of 4

Thread: VBA - Excel: Disable Internet / Google

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0
    Last edited by DocAElstein; 07-12-2023 at 05:10 PM.

  2. #2

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Thumbs up

    Hi sanits591

    I dont require a pseudocode, I need a code or else some VBA code.

    Regards : Technicalupload

  4. #4
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0
    Insert one sheet with name "Secret" to your workbook, then use the below code for your workbook.

    In the thisworkbook objects:
    Code:
    Private Sub Workbook_Open()
    
    Call Internet_Connectivity
    
    If Sheets("secret").Range("c1").Value = "Connected" Then
    ThisWorkbook.Close   ' close the Workbook
    End If
    
    End Sub
    In standard module:
    Code:
    Private Declare Function InternetGetConnectedState _
       Lib "wininet.dll" (ByRef dwflags As Long, _
       ByVal dwReserved As Long) As Long
    Private Const INTERNET_CONNECTION_MODEM As Long = &H1
    Private Const INTERNET_CONNECTION_LAN As Long = &H2
    Private Const INTERNET_CONNECTION_PROXY As Long = &H4
    Private Const INTERNET_CONNECTION_OFFLINE As Long = &H20
    Function IsInternetConnected() As Boolean
        Dim L As Long
        Dim R As Long
        R = InternetGetConnectedState(L, 0&)
        If R = 0 Then
            IsInternetConnected = False
        Else
            If R <= 4 Then
                IsInternetConnected = True
            Else
                IsInternetConnected = False
            End If
        End If
    End Function
    'You would call this in your code with something like
     
    Sub Internet_Connectivity()
        If IsInternetConnected() = True Then
             'MsgBox "Internet is Connected, the workbook shall be closed"
             Sheets("secret").Range("c1").Value = "Connected"
        Else
            Sheets("secret").Range("c1").Value = "Not Connected"
        
        End If
    End Sub
    Hope this shall help you with some of your requirements.

    Thanks!

Similar Threads

  1. Replies: 30
    Last Post: 04-15-2019, 07:36 PM
  2. VBA IE Internet Explorer Automation Through ElementID
    By mrmmickle1 in forum Excel Help
    Replies: 3
    Last Post: 01-22-2013, 06:20 AM
  3. Looping Through Each Internet Explorer
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 3
    Last Post: 03-27-2012, 07:30 PM
  4. Disable OUTLOOK spellcheck using VBA
    By Varun.Dandona in forum Outlook Help
    Replies: 5
    Last Post: 10-25-2011, 10:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •