Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://excel-egy.com/forum/t3818
- ---------------------------------
- #If VBA7 Then
- Private Declare PtrSafe Function InternetSetOptionA Lib "wininet.dll" (ByVal hInternet As Long, ByVal lOption As Long, ByVal sBuffer As String, ByVal lBufferLength As Long) As Integer
- #Else
- Private Declare Function InternetSetOptionA Lib "wininet.dll" (ByVal hInternet As Long, ByVal lOption As Long, ByVal sBuffer As String, ByVal lBufferLength As Long) As Integer
- #End If
- Sub Change_Proxy_Settings_Using_VBA()
- Dim vUser1, vUser2, ans%
- ans = MsgBox("To Enable Proxy Settings Click 'Yes'." & Chr(13) & "To Disable Proxy Settings Click 'No'", vbYesNoCancel + vbQuestion)
- If ans = vbYes Then
- vUser1 = InputBox("Enter The Proxy Server You Want To Use.", "Proxy Server", "http://excel-egy.com:8080")
- If vUser1 = "" Then Exit Sub
- Rem Proxy Server Exceptions
- MsgBox "The URLs You Would Like To Override Should Be In Cell A1. Use Semi-Colons (;) To Separate Entries", 64
- vUser2 = ActiveSheet.Range("A1").Value
- ProxySettings True, vUser1, vUser2
- ElseIf ans = vbNo Then
- ProxySettings False
- Else
- Exit Sub
- End If
- End Sub
- Sub ProxySettings(bEnable As Boolean, Optional sProxyServer, Optional sProxyOverride)
- Dim objShell As Object, regPath$, regServer$, regOverride$, regEnable$
- Set objShell = CreateObject("WScript.Shell")
- InternetSetOptionA 0, 39, 0, 0
- regPath$ = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\"
- regServer = regPath$ & "ProxyServer"
- regOverride = regPath$ & "ProxyOverride"
- regEnable = regPath$ & "ProxyEnable"
- If bEnable = False Then GoTo Skipper
- objShell.RegWrite regServer, sProxyServer, "REG_SZ"
- objShell.RegWrite regOverride, sProxyOverride & "<local>", "REG_SZ"
- Skipper:
- objShell.RegWrite regEnable, IIf(bEnable, "1", "0"), "REG_DWORD"
- MsgBox "Proxy Is " & IIf(bEnable, "Enabled", "Disabled")
- Shell "C:\Program Files\Internet Explorer\iexplore.exe -nohome", vbNormalFocus
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement