-
도로명주소 가져오기VB(A) 2018. 2. 13. 15:19
주소가 중구난방이거나 정식 도로명주소 등이 필요할 때 유용한 함수를 만들었다.
juso.go.kr에서 파싱해오는 방식임
Option ExplicitFunction ConvertAddress(MyText As String, Optional WhichAddress As Integer) As String'Dim oHtml As New HTMLDocumentDim oHtml As ObjectDim myURL As String, postData As StringDim winHttpReq As ObjectDim tmp As StringmyURL = "http://www.juso.go.kr/support/AddressMainSearch.do?searchType=TOTAL" '주소 변환 사이트'postData = "searchKeyword=" & WorksheetFunction.EncodeURL(MyText) '검색어(EncodeURL 은 2013 이상에서 사용 가능)postData = "searchKeyword=" & ENDECODingURL(MyText)Set oHtml = CreateObject("htmlfile")Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")With winHttpReq '검색어로 웹소스 가져오기.Open "POST", myURL, False.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded".Send (postData)oHtml.body.innerHTML = .responseTextEnd WithSet winHttpReq = NothingSelect Case WhichAddressCase 2: tmp = oHtml.getElementById("lndnAddr1").Value '2일 때 구주소Case Else: tmp = oHtml.getElementById("rnAddr1").Value '나머지는 신주소End Selecttmp = Replace(tmp, "<b>", "")tmp = Replace(tmp, "</b>", "")ConvertAddress = tmpEnd FunctionFunction ENDECODingURL(varText As String, Optional blnEncode = True)Static objHtmlfile As ObjectIf objHtmlfile Is Nothing ThenSet objHtmlfile = CreateObject("htmlfile")With objHtmlfile.parentWindow.execScript "function encode(s) {return encodeURIComponent(s)}", "jscript".execScript "function decode(s) {return decodeURIComponent(s)}", "jscript"End WithEnd IfIf blnEncode ThenENDECODingURL = objHtmlfile.parentWindow.encode(varText)ElseENDECODingURL = objHtmlfile.parentWindow.decode(varText)End IfEnd Functioncs 'VB(A)' 카테고리의 다른 글
[추가기능] 주소변환(지번주소, 도로명주소, 우편번호) (2) 2018.06.22 [정규식] 숫자를 한글로 변환 (0) 2018.02.23 여러 시트를 쉽게 이동하기 (0) 2018.01.05 [정규식] 텍스트 파일을 조건에 맞게 쪼개서 가져오기 (0) 2017.12.31 웹페이지 파싱 (0) 2017.09.23 댓글