엑셀 텍스트(입력키) 매크로

네이버의 검색순위를 조작할때, 작업을 한다고들 하는데, 매크로를 사용한다는건 공공연한 비밀이다.
비슷한 맥락으로 엑셀VBA로 키를 입력할 수 있는데, 엑셀 시트에 입력한 값을 던져줄 수 있다는 장점이 있다.

이는 인터넷 브라우저에서도 쓸 수 있는데, 특히 같은 회사에서 나온 인터넷 익스플로러에 친화적인 것으로 보인다.
(불행히도 지금은 잘 쓰이지 않지만…)

아무도 쓸일은 없겠지만, 사용된 코드를 메모해 두었다.

Sub typeWriter()

    Dim win
    win = Shell("c:\windows\notepad.exe", vbNormalFocus)
    Dim txt As String
    Dim count As Integer
    Dim txtArr() As String

    txt = "this is typeWriter effect Test"
    count = Len(txt)
    ReDim txtArr(count)

    Call sleep

    For x = 1 To count
        txtArr(x) = Mid(txt, x, 1)
        If (txtArr(x) = " ") Then
            Call sleep
        End If
        SendKeys txtArr(x), True
    Next x
End Sub

Sub cr()
    Dim win
    win = Shell("c:\windows\notepad.exe", vbNormalFocus)

    Call sleep
        SendKeys "ID값 : " + Cells(2, 2).Value, True
    Call sleep
        SendKeys "{ENTER}", True
    Call sleep
        SendKeys "PW값 : " + Cells(2, 3).Value, True
    Call sleep
        SendKeys "{ENTER}", True
        SendKeys "끝!", True

End Sub

Function sleep()
    Application.Wait Now + TimeSerial(0, 0, 1)
End Function

Sub NaverLogin()
    Dim mywindow
    Set mywindow = CreateObject("InternetExplorer.Application")

    With mywindow
        .Visible = True
        .Navigate "https://nid.naver.com/nidlogin.login"
        .Height = 1000
        .Width = 1000

        ' 대기방법 #1 : 4초 강제로 대기
         ' Application.Wait Now + TimeSerial(0, 0, 4)
        ' 대기방법 #2
        Do While mywindow.Busy
            DoEvents
        Loop
    End With

    Set mypage = mywindow.document

    With mypage.all
        .Item("id").Value = ActiveSheet.Cells(3, 2).Value
        .Item("pw").Value = ActiveSheet.Cells(3, 3).Value
    End With

    Call sleep

    SendKeys "{ENTER}", True

End Sub


끝.