Option Explicit
Private Declare PtrSafe Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32.dll" Alias "Sleep" (ByVal dwMilliseconds As Long)
Public Sub UIAutomation_Fill_First_Form_Field(AcrobatHwnd As LongPtr, fieldValue As String)
#Else
Public Sub UIAutomation_Fill_First_Form_Field(AcrobatHwnd As LongPtr, fieldValue As String)
Dim UIAuto As IUIAutomation
Dim AcrobatMain As IUIAutomationElement
Dim ControlTypeCond As IUIAutomationCondition
Dim Document As IUIAutomationElement
Dim Fields As IUIAutomationElementArray
Dim field As IUIAutomationElement
Dim i As Long
Set UIAuto = New CUIAutomation
Set AcrobatMain = UIAuto.ElementFromHandle(ByVal AcrobatHwnd)
Set ControlTypeCond = UIAuto.CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_DocumentControlTypeId)
Do
Set Document = AcrobatMain.FindFirst(TreeScope_Descendants, ControlTypeCond)
DoEvents
Sleep 200
Loop While Document Is Nothing
Set ControlTypeCond = UIAuto.CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_EditControlTypeId)
Set Fields = Document.FindAll(TreeScope_Subtree, ControlTypeCond)
Debug.Print Fields.Length
Sleep 200
i = 0
Do While i < Fields.Length - 1
Set field = Fields.GetElement(i)
If Not field.GetCurrentPropertyValue(UIA_ValueIsReadOnlyPropertyId) Then
field.SetFocus
SendKeys "^a{DELETE}", True
Sleep 100
DoEvents
SendKeys fieldValue
DoEvents
Sleep 100
Exit Do
End If
i = i + 1
Loop
AcrobatMain.SetFocus
SendKeys "^(s)", True
End Sub