title: How to use sendkeys with vba excel
body: <p>this is my code for excel (a) actually what i am trying is to send data to another excel (b) witch is locked (i can only press command &amp; message  buttons)  and i have no access to the code (vba),  i can only insert my data from (a)  and  for  step_1 i have to press a), b), d), e) command buttons and c) a message box in order to go to step_2 where i have to  one more time in order to get my results. Finally, when my results are ready i can't find the way to copy them from (b) to (a)
      PROJECT.xls  = b
      ThisWorkbook = a</p>
  
  <pre><code>Public Declare Function SetCursorPos Lib "User32" (ByVal x As Long, ByVal y As Long) As Long
  Public Declare Sub mouse_event Lib "User32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
   Public Const MOUSEEVENTF_LEFTDOWN = &amp;H2
   Public Const MOUSEEVENTF_LEFTUP = &amp;H4
      Public Const MOUSEEVENTF_RIGHTDOWN As Long = &amp;H8
      Public Const MOUSEEVENTF_RIGHTUP As Long = &amp;H10
  Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  
  Sub Generate_XL(start_row As Integer, end_row As Integer)
  
      Dim xlWorkbookNewFileName As String
      Dim i As Integer
          Dim cmt As Comment
          Set cmt = ActiveCell.Comment
      For i = start_row To end_row
          Dim wb As Workbook
          Dim wb1 As Workbook
          Dim FileName As String
          Dim FilePath As String
          FileName = Cells(i, 1).Value
  
  
                               If Cells(i, 20) = "s0" Then
                                      Set wb = ThisWorkbook
                                      Set wb1 = Workbooks.Open("H:\PROJECT.xls")
  
  'STEP_1
  Worksheets("sheetA").Select
      ' max X = 1250
      ' max Y = 1250
  Application.DisplayAlerts = False
  
      SetCursorPos 1050, 350  'x and y position
  mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
  Sleep 50
  mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
  IsTimeToStop = True
  Application.Wait (Now() + TimeValue("00:00:01"))
          Worksheets("Menu").Select
  SetCursorPos 150, 530   'x and y position
  mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
  Sleep 50
  mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
  IsTimeToStop = True
  Application.Wait (Now() + TimeValue("00:00:01"))
      If cmt Is Nothing Then
  Application.Wait (Now() + TimeValue("00:00:01"))
  SendKeys "~"  '   pataw &lt;ENTER&gt;
  End If
  IsTimeToStop = True
  Application.Wait (Now() + TimeValue("00:00:01"))
      SetCursorPos 150, 610 'x and y position
  mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
  Sleep 50
  mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
  IsTimeToStop = True
  Application.Wait (Now() + TimeValue("00:00:01"))
       SetCursorPos 150, 650 'x and y position
  mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
  Sleep 50
  mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
  IsTimeToStop = True
  Application.Wait (Now() + TimeValue("00:00:01"))
  
  
  'STEP_2
          SetCursorPos 505, 434 'x and y position
      mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
      Sleep 50
      mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
      IsTimeToStop = True
  SendKeys "~"
  SendKeys "~"
      SendKeys "{RIGHT 5}"
           SendKeys "^c"
  IsTimeToStop = True
  Application.Wait (Now() + TimeValue("00:00:01"))
  
  
  'SendKeys "%{ }N"  ' = (ALT&amp;tab)
  'SendKeys "^a"
  'SendKeys "^a"
  'Range("l2").Select
  'Cells(i, 12).Select
  
                               ' ElseIf Cells(i, 20) = "a0" Then
                               ' MsgBox ("REST")
                               '       Else: Cells(i, 20) = "x2" Then
                               ' MsgBox ("NOTHING)
                          End If  'Select
      Next i
  End Sub
  </code></pre>