It was working before but I now I keep getting the error code "Automation Error; Unspecified Error" when i set the oElements on line 12 of the sub. Any thoughts?
Sub SavePath(ByVal strWindowID As String, ByVal strObjectName As String, ByVal strAutomationId As String, ByVal strLocalizeType As String, ByVal strValue As String)
Dim intElementCounter As Integer
Dim strTreeItem1 As String
Dim strTreeitem2 As String
Dim strTreeitem3 As String
strThiswbFileName = ActiveWorkbook.Name
strThiswbCaption = Application.Caption
Set oTW = oAutomation.ControlViewWalker
Set oCondition = oAutomation.CreatePropertyCondition(UIAutomationClient.UIA_NamePropertyId, strObjectName)
Set oElements = oAutomation.GetRootElement.FindAll(TreeScope_Descendants, oCondition)
For intElementCounter = 0 To oElements.length - 1
If oElements.GetElement(intElementCounter).CurrentName = strObjectName Then
If oElements.GetElement(intElementCounter).CurrentAutomationId = strAutomationId Then
If oElements.GetElement(intElementCounter).CurrentLocalizedControlType = strLocalizeType Then
Set oPatternValue = oElements.GetElement(intElementCounter).GetCurrentPattern(UIAutomationClient.UIA_ValuePatternId)
oPatternValue.SetValue strValue
Exit Sub
End If
End If
End If
Next
End Sub
My references are
- Visual Basic for Applications
- Microsoft Excel 14.0 Object Library
- OLE Automation
- Microsoft ActiveX Data Objects 2.0 Library
- Microsoft HTML Object Library
- Microsoft Internet Controls
- Microsoft Visual Basic for Applications Extensiblity 5.3
- UIAutomationClient