SendKeys to using Window Caption

Mstg007

Active Member
Joined
Dec 30, 2013
Messages
383
I am trying to use sendkeys to a third party application that is windows based. There is another windows inside the main window I would like to use sendkeys to. I have used the WinSpy++ to get the properties of the box I want to send the keys too. The Handle is (001B0C2E) and caption is (Create from Object). The Basic sendkeys:

Code:
DoEvents
Application.Wait (Now + TimeValue("0:00:03"))
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{ENTER}", True
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{ENTER}", True

Thanks for any help!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
those may work, but i doubt anyone can tell what the application is, how you are setting it up to be interacted with

i also suspect that unless sendkeys is a pair, trying to send four tabs together dosen't work (stand to be corrected)
 
Upvote 0
Thanks for responding. This code worked with the previous versions of my cad package. We recently upgrade it and now it will not sendkeys like it did before. Also, all my references have been updated to the new version as well.

Sorry if it looks Clunky.

Code:
Option Explicit
'API Declaration
Public AcadApp As AcadApplication
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Private Const MOUSEEVENTF_RIGHTUP As Long = &H10
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Sub Civil3D_Create_Catchment()

Call Catchment
'Application.Visible = False
Dim i As Integer
With Prog_bar
    'SET MIN value to 0
    .ProgressBar1.Min = 0
    'SET Max value as per your requirement
    .ProgressBar1.Max = 15000
    .Show vbModeless
    '.ScrollBars = fmScrollBarsVertical
    ' run a loop to display progres bar
    For i = 1 To 15000
        'change the value of progress bar to show the progress using fill color
        .ProgressBar1.Value = i
        ' chnage the caption of user form to display the percentage of task completed
        .Caption = VBA.Format(i / Prog_bar.ProgressBar1.Max, "0%") & "  Complete"
        DoEvents ' DoEvents allows the UserForm to update.
    Next
End With
' task finish unload progress bar
Unload Prog_bar
'Application.Visible = True
' Place Macro to Run After Count Down
Call Catchment_Storm_SendKeys
End Sub





Sub Catchment()

 On Error Resume Next
 Set AcadApp = GetObject(, "AutoCAD.Application")
 If Err Then
 Err.Clear
 Set AcadApp = CreateObject("AutoCAD.Application")
 End If

 AppActivate AcadApp.Caption
 AcadApp.Visible = True
 AcadApp.Application.WindowState = acNorm
 AcadApp.ActiveSpace = acModelSpace


 If AcadApp.Documents.Count = 0 Then
 AcadApp.Documents.Add
 End If

 AcadApp.ActiveDocument.SendCommand "_CREATECATCHMENTFROMOBJECT" & vbCr
 

End Sub


Sub Catchment_Storm_SendKeys()
   Dim myApp As String

DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{ENTER}", True
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{ENTER}", True
Sleep 250
SendKeys "{C}{_}{D}", True
Sleep 250
SendKeys "{TAB}", True
Sleep 250
SendKeys "{ENTER}", True
Sleep 250
SendKeys "{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{ENTER}", True
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{DOWN}{RIGHT}{DOWN}{TAB}", True
Sleep 250
SendKeys "{5}", True
Sleep 250
SendKeys ("{/}"), True
Sleep 250
SendKeys "{6}", True
Sleep 250
SendKeys "{0}", True
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{ENTER}", True

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top