{"id":4944,"date":"2014-10-16T12:36:39","date_gmt":"2014-10-16T03:36:39","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=4944"},"modified":"2017-12-20T10:43:51","modified_gmt":"2017-12-20T01:43:51","slug":"office-%e3%82%af%e3%83%aa%e3%83%83%e3%83%97%e3%83%9c%e3%83%bc%e3%83%89%e3%82%92%e3%83%9e%e3%82%af%e3%83%ad%e3%81%a7%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8bui-automation","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=4944","title":{"rendered":"Office \u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u3092\u30de\u30af\u30ed\u3067\u64cd\u4f5c\u3059\u308b(UI Automation)"},"content":{"rendered":"<p>\u4ee5\u524d<a href=\"http:\/\/msdn.microsoft.com\/ja-jp\/library\/cc401822.aspx\" title=\"Microsoft Active Accessibility \uff1a\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\" target=\"_blank\">MSAA<\/a>\u3092\u5229\u7528\u3057\u3066Office \u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u3092\u64cd\u4f5c\u3059\u308b\u30de\u30af\u30ed\u3092\u66f8\u3044\u305f\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001<\/p>\n<p><strong>\u30fbOffice 2007\/2010\u30fb\u30ea\u30dc\u30f3\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba \u521d\u5fc3\u8005\u5099\u5fd8\u9332<\/strong><br \/>\n<a href=\"\/\/www.ka-net.org\/office\/of55.html\" title=\"Office \u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u3092\u30de\u30af\u30ed\u3067\u64cd\u4f5c\u3059\u308b(Office 2003)\" target=\"_blank\">\/\/www.ka-net.org\/office\/of55.html<\/a><br \/>\n<strong>\u30fbOffice 2007\/2010\u30fb\u30ea\u30dc\u30f3\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba \u521d\u5fc3\u8005\u5099\u5fd8\u9332<\/strong><br \/>\n<a href=\"\/\/www.ka-net.org\/office\/of56.html\" title=\"Office \u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u3092\u30de\u30af\u30ed\u3067\u64cd\u4f5c\u3059\u308b(Office 2007\u4ee5\u964d)\" target=\"_blank\">\/\/www.ka-net.org\/office\/of56.html<\/a><\/p>\n<p>\u4eca\u56de\u306f\u4e0a\u8a18\u30de\u30af\u30ed\u3092UI Automation\u3092\u4f7f\u3046\u5f62\u306b\u66f8\u304d\u76f4\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><span style=\"color: #ff0000; font-weight: bold;\">\u203b UIAutomationClient(UIAutomationCore.dll)\u8981\u53c2\u7167<\/span><br \/>\n<span style=\"color: #ff0000; font-weight: bold;\">\u203b UIAutomationClient\u53c2\u7167\u6642\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u306f\u300c<a href=\"\/\/www.ka-net.org\/blog\/?p=4617\" title=\"UIAutomationClient\u53c2\u7167\u6642\u306bDLL\u8aad\u307f\u8fbc\u307f\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u6642\u306e\u5bfe\u51e6\u6cd5\" target=\"_blank\">UIAutomationClient\u53c2\u7167\u6642\u306bDLL\u8aad\u307f\u8fbc\u307f\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u6642\u306e\u5bfe\u51e6\u6cd5<\/a>\u300d\u53c2\u7167<\/span><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Private Sub DoActionOfficeClipboard(ByVal ButtonName As String)\r\n'Office\u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\r\n  Dim uiAuto As UIAutomationClient.CUIAutomation\r\n  Dim accClipboard As Office.IAccessible\r\n  Dim elmClipboard As UIAutomationClient.IUIAutomationElement\r\n  Dim elmButton As UIAutomationClient.IUIAutomationElement\r\n  Dim cndButtons As UIAutomationClient.IUIAutomationCondition\r\n  Dim aryButtons As UIAutomationClient.IUIAutomationElementArray\r\n  Dim ptnAcc As UIAutomationClient.IUIAutomationLegacyIAccessiblePattern\r\n  Dim i As Long\r\n  \r\n  Set elmButton = Nothing '\u521d\u671f\u5316\r\n  Set uiAuto = New UIAutomationClient.CUIAutomation\r\n  With Application\r\n    .CommandBars(&quot;Office Clipboard&quot;).Visible = True\r\n    DoEvents\r\n    Set accClipboard = .CommandBars(&quot;Office Clipboard&quot;)\r\n  End With\r\n  Set elmClipboard = uiAuto.ElementFromIAccessible(accClipboard, 0)\r\n  Set cndButtons = uiAuto.CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_ButtonControlTypeId)\r\n  Set aryButtons = elmClipboard.FindAll(TreeScope_Subtree, cndButtons)\r\n  For i = 0 To aryButtons.Length - 1\r\n    If aryButtons.GetElement(i).CurrentName = ButtonName Then\r\n      Set elmButton = aryButtons.GetElement(i)\r\n      Exit For\r\n    End If\r\n  Next\r\n  If elmButton Is Nothing Then Exit Sub\r\n  If elmButton.CurrentIsEnabled &lt;&gt; False Then\r\n    Set ptnAcc = elmButton.GetCurrentPattern(UIA_LegacyIAccessiblePatternId)\r\n    ptnAcc.DoDefaultAction\r\n  End If\r\nEnd Sub\r\n\r\nPrivate Sub PasteOfficeClipboardListItem(ByVal ItemNum As Long)\r\n'Office\u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30a2\u30a4\u30c6\u30e0\u3092\u8cbc\u308a\u4ed8\u3051\r\n  Dim aryListItems As UIAutomationClient.IUIAutomationElementArray\r\n  Dim ptnAcc As UIAutomationClient.IUIAutomationLegacyIAccessiblePattern\r\n  \r\n  Set aryListItems = GetOfficeClipboardListItems\r\n  If (aryListItems.Length = 1) And _\r\n     (InStr(aryListItems.GetElement(0).CurrentName, &quot;\u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u306f\u7a7a\u3067\u3059&quot;)) Then\r\n    MsgBox &quot;\u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u306f\u7a7a\u3067\u3059\u3002&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, vbCritical + vbSystemModal\r\n    Exit Sub\r\n  End If\r\n  If (ItemNum &gt; aryListItems.Length) Or _\r\n     (ItemNum &lt; 1) Then\r\n    MsgBox &quot;\u73fe\u5728\u6307\u5b9a\u3067\u304d\u308b\u756a\u53f7\u306f &#x5B;1 - &quot; &amp; aryListItems.Length &amp; &quot;]\u307e\u3067\u3067\u3059\u3002&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, vbCritical + vbSystemModal\r\n    Exit Sub\r\n  End If\r\n  Set ptnAcc = aryListItems.GetElement(ItemNum - 1).GetCurrentPattern(UIA_LegacyIAccessiblePatternId)\r\n  ptnAcc.DoDefaultAction\r\nEnd Sub\r\n\r\nPrivate Function GetOfficeClipboardListItems() As UIAutomationClient.IUIAutomationElementArray\r\n'Office\u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u30ea\u30b9\u30c8\u53d6\u5f97\r\n  Dim uiAuto As UIAutomationClient.CUIAutomation\r\n  Dim accClipboard As Office.IAccessible\r\n  Dim elmClipboard As UIAutomationClient.IUIAutomationElement\r\n  Dim cndListItems As UIAutomationClient.IUIAutomationCondition\r\n  \r\n  Set uiAuto = New UIAutomationClient.CUIAutomation\r\n  With Application\r\n    .CommandBars(&quot;Office Clipboard&quot;).Visible = True\r\n    DoEvents\r\n    Set accClipboard = .CommandBars(&quot;Office Clipboard&quot;)\r\n  End With\r\n  Set elmClipboard = uiAuto.ElementFromIAccessible(accClipboard, 0)\r\n  Set cndListItems = uiAuto.CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_ListItemControlTypeId)\r\n  Set GetOfficeClipboardListItems = elmClipboard.FindAll(TreeScope_Subtree, cndListItems)\r\nEnd Function<\/pre>\n<p>\u4f7f\u3044\u65b9\u306f\u4e0b\u8a18\u306e\u901a\u308a\u3067\u3001MSAA\u306e\u30b3\u30fc\u30c9\u306b\u6bd4\u3079\u308b\u3068\u3001\u5927\u5206\u30b7\u30f3\u30d7\u30eb\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Public Sub Test1()\r\n'Office\u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u306b\u3042\u308b\u30a2\u30a4\u30c6\u30e0\u5217\u6319\r\n  Dim aryListItems As UIAutomationClient.IUIAutomationElementArray\r\n  Dim i As Long\r\n  \r\n  Set aryListItems = GetOfficeClipboardListItems\r\n  For i = 0 To aryListItems.Length - 1\r\n    Debug.Print i + 1, aryListItems.GetElement(i).CurrentName\r\n  Next\r\nEnd Sub\r\n\r\nPublic Sub Test2()\r\n  'DoActionOfficeClipboard &quot;\u3059\u3079\u3066\u8cbc\u308a\u4ed8\u3051&quot;\r\n  DoActionOfficeClipboard &quot;\u3059\u3079\u3066\u30af\u30ea\u30a2&quot;\r\nEnd Sub\r\n\r\nPublic Sub Test3()\r\n'20\u756a\u76ee\u306e\u30a2\u30a4\u30c6\u30e0\u3092\u8cbc\u308a\u4ed8\u3051\r\n  PasteOfficeClipboardListItem 20\r\nEnd Sub<\/pre>\n<h4 class=\"style4a\">\u95a2\u9023\u8a18\u4e8b<\/h4>\n<div class=\"cardlink\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=9385\"><div class=\"cardlink_thumbnail\"><img src='https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-OfficeVBA-120x120.png' alt='Office \u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u3092\u30de\u30af\u30ed\u3067\u64cd\u4f5c\u3059\u308b(MSAA)' width=120 height=120 \/><\/a><\/div><div class=\"cardlink_content\"><span class=\"timestamp\">2017.12.20<\/span><div class=\"cardlink_title\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=9385\">Office \u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u3092\u30de\u30af\u30ed\u3067\u64cd\u4f5c\u3059\u308b(MSAA) <\/a><\/div><div class=\"cardlink_excerpt\">MSDN\u30d5\u30a9\u30fc\u30e9\u30e0\u306b\u8cea\u554f\u304c\u3042\u308a\u307e\u3057\u305f\u304c\u3001Office \u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u3092\u30de\u30af\u30ed\u3067\u64cd\u4f5c\u3059\u308b\u306e\u306f\u4e00\u5b9a\u306e\u9700\u8981\u304c\u3042\u308b\u306e\u3067\u3001\u4ee5\u524d\u66f8\u3044\u305f\u30de\u30af\u30ed(\u4e0b\u8a18\u53c2\u7167)\u3092\u66f8\u304d\u76f4\u3057\u3066\u307f\u307e\u3057\u305f\u3002\r\n\r\n\r\nOffice \u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u3092\u30de\u30af\u30ed\u3067\u64cd\u4f5c\u3059\u308b(Office 2003)\r\nhttp:...<\/div><\/div><div class=\"cardlink_footer\"><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"\u4ee5\u524dMSAA\u3092\u5229\u7528\u3057\u3066Office \u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u3092\u64cd\u4f5c\u3059\u308b\u30de\u30af\u30ed\u3092\u66f8\u3044\u305f\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001 \u30fbOffice 2007\/2010\u30fb\u30ea\u30dc\u30f3\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba \u521d\u5fc3\u8005\u5099\u5fd8\u9332 \/\/www.ka-net.org\/office\/of [&hellip;]","protected":false},"author":1,"featured_media":7111,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"\u4e45\u3005\u306e\u30d6\u30ed\u30b0\u66f4\u65b0\u3067\u3059\u3002 [Office \u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u3092\u30de\u30af\u30ed\u3067\u64cd\u4f5c\u3059\u308b(UI Automation)]","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,48,49,58],"tags":[],"class_list":["post-4944","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-excel-office","category-word-office","category-powerpoint"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Excel.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-1hK","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4944"}],"version-history":[{"count":2,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4944\/revisions"}],"predecessor-version":[{"id":9387,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4944\/revisions\/9387"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7111"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}