[엑셀VBA] 내부네트워크에서만 매크로 실행 (running macro only in internal network)
본문 바로가기
코딩/엑셀 VBA

[엑셀VBA] 내부네트워크에서만 매크로 실행 (running macro only in internal network)

by BizAnalytics 2014. 6. 15.
반응형

업무상 특정 매크로를 만들었는데,

외부 유출 되면 곤란한 경우 혹은 내부 네트워크에서만 실행하도록 해야할 경우 있습니다.

 

그런 경우를 위해서 사용자 정의 함수를 만들어보았습니다.

내부 네트워크에서만 접근 가능한 주소를 아래 URL에 기재하시고 VBA에서 함수 호출하시면 됩니다.

 

접속이 되는 경우 OK가 반환되고,접속이 안되는 경우 Error가 반환됩니다.

 

조건문으로 OK가 반환되는 경우 다음 구문으로 넘어가시게 하면 됩니다.

 


 

I had need to block running macros when user isn't in the internal network.

So I made a user defined function which check that user is in the internal network or not.

You should replace URL with the address of the internal network page.

If the macro succeed to connect to the address, it returns "OK", otherwise it returns "Error".

 


 

 

 

Public Function connection_check()

 

 

Dim WinHttp As New WinHttp.WinHttpRequest
URL = http://192.168.0.1"     '/ you should input the address which

  

On Error GoTo ErrorHandler

 

WinHttp.Open "GET", URL
WinHttp.send
WinHttp.waitForResponse

 

Debug.Print WinHttp.StatusText
connect_check = WinHttp.StatusText

 

Exit Function

 

ErrorHandler:

 

Debug.Print "Error"
connect_check = "Error"

 

Exit Function

 

End Function
반응형