{"id":10042,"date":"2018-02-22T15:00:53","date_gmt":"2018-02-22T06:00:53","guid":{"rendered":"https:\/\/www.ka-net.org\/blog\/?p=10042"},"modified":"2018-02-22T15:44:25","modified_gmt":"2018-02-22T06:44:25","slug":"vba%e3%83%97%e3%83%ad%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88%e3%82%92%e3%80%8c%e5%b1%95%e9%96%8b%e3%81%99%e3%82%8b%e3%80%8dvba%e3%83%9e%e3%82%af%e3%83%ad","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=10042","title":{"rendered":"VBA\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u300c\u5c55\u958b\u3059\u308b\u300dVBA\u30de\u30af\u30ed"},"content":{"rendered":"<p><a href=\"https:\/\/social.msdn.microsoft.com\/Forums\/ja-JP\/home?forum=vbajp\" title=\"Msdn \u30d5\u30a9\u30fc\u30e9\u30e0 - Visual Basic for Application(VBA)\" target=\"_blank\">MSDN\u30d5\u30a9\u30fc\u30e9\u30e0<\/a>\u306b<a href=\"https:\/\/social.msdn.microsoft.com\/Forums\/ja-JP\/vbajp\/thread\/9dc9d029-cb6a-4e4d-9c81-3b899db899a0\" title=\"Excel2016 \uff62PERSONAL.XLSB\uff63VBA\u304b\u3089VBE\u3092\u64cd\u4f5c\u3059\u308b(\u958b\u304f)\" target=\"_blank\">\u9762\u767d\u3044\u8cea\u554f<\/a>\u304c\u3042\u308a\u307e\u3057\u305f\u3002<br \/>\nVBE\u30fb\u30d7\u30ed\u30b8\u30a7\u30af\u30c8 \u30a8\u30af\u30b9\u30d7\u30ed\u30fc\u30e9\u30fc\u306b\u3042\u308b\u6307\u5b9a\u3057\u305f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u30de\u30af\u30ed\u3067<span style=\"color: #ff0000; font-weight: bold;\">\u201c\u5c55\u958b\u201d<\/span>\u3057\u305f\u3044(\u300c\uff0b\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af)\u3001\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u30de\u30af\u30ed\u3067\u3053\u306e\u4f5c\u696d\u3092\u884c\u3046\u5fc5\u8981\u6027\u304c\u672c\u5f53\u306b\u3042\u308b\u306e\u304b\u3069\u3046\u304b\u306f\u79c1\u306b\u306f\u5206\u304b\u308a\u307e\u305b\u3093\u304c\u3001\u3068\u308a\u3042\u3048\u305a\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">'UIAutomationClient(UIAutomationCore.dll)\u8981\u53c2\u7167\r\nOption Explicit\r\n\r\nPublic Sub Sample()\r\n  ExpandVbaProject &quot;ExpandVbaProject&quot;, False\r\nEnd Sub\r\n\r\nPrivate Sub ExpandVbaProject(ByVal ProjectName As String, _\r\n                             Optional ByVal ExpandState As Boolean = True)\r\n  Dim uiAuto As CUIAutomation\r\n  Dim elmVbeWindow As IUIAutomationElement\r\n  Dim elmPjWindow As IUIAutomationElement\r\n  Dim elmSysTree As IUIAutomationElement\r\n  Dim aryTreeItems As IUIAutomationElementArray\r\n  Dim ptnExpand As IUIAutomationExpandCollapsePattern\r\n  Dim hVbeWindow As LongPtr\r\n  Dim w As Object 'VBIDE.Window\r\n  Dim i As Long\r\n  Const vbext_wt_ProjectWindow = 6\r\n  \r\n  Application.CommandBars.FindControl(ID:=1695).Execute 'VBE\u8868\u793a\r\n  On Error Resume Next\r\n  hVbeWindow = Application.VBE.MainWindow.Hwnd\r\n  Select Case Err.Number\r\n    Case 1004, 6068, -2147188160\r\n      MsgBox &quot;&#x5B;\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3 \u30bb\u30f3\u30bf\u30fc\u306e\u8a2d\u5b9a]\u304b\u3089&quot; &amp; vbNewLine &amp; vbNewLine &amp; _\r\n             &quot;\u3010VBA \u30d7\u30ed\u30b8\u30a7\u30af\u30c8 \u30aa\u30d6\u30b8\u30a7\u30af\u30c8 \u30e2\u30c7\u30eb\u3078\u306e\u30a2\u30af\u30bb\u30b9\u3092\u4fe1\u983c\u3059\u308b\u3011&quot; &amp; vbNewLine &amp; vbNewLine &amp; _\r\n             &quot;\u306b\u30c1\u30a7\u30c3\u30af\u3092\u5165\u308c\u305f\u5f8c\u3001\u518d\u5ea6\u30de\u30af\u30ed\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002&quot;, vbExclamation + vbSystemModal\r\n      Exit Sub\r\n  End Select\r\n  On Error GoTo 0\r\n  \r\n  '\u30d7\u30ed\u30b8\u30a7\u30af\u30c8 \u30a8\u30af\u30b9\u30d7\u30ed\u30fc\u30e9\u30fc\u8868\u793a\r\n  For Each w In Application.VBE.Windows\r\n    If w.Type = vbext_wt_ProjectWindow Then\r\n      w.Visible = True\r\n      Exit For\r\n    End If\r\n  Next\r\n  \r\n  Set uiAuto = New UIAutomationClient.CUIAutomation\r\n  Set elmVbeWindow = uiAuto.ElementFromHandle(ByVal hVbeWindow)\r\n  If elmVbeWindow Is Nothing Then Exit Sub\r\n  Set elmPjWindow = GetElement(uiAuto, _\r\n                               elmVbeWindow, _\r\n                               UIA_ClassNamePropertyId, _\r\n                               &quot;PROJECT&quot;, _\r\n                               UIA_PaneControlTypeId)\r\n  If elmPjWindow Is Nothing Then Exit Sub\r\n  Set elmSysTree = GetElement(uiAuto, _\r\n                              elmPjWindow, _\r\n                              UIA_ClassNamePropertyId, _\r\n                              &quot;SysTreeView32&quot;, _\r\n                              UIA_TreeControlTypeId)\r\n  If elmSysTree Is Nothing Then Exit Sub\r\n  Set aryTreeItems = elmSysTree.FindAll(TreeScope_Children, _\r\n                                        uiAuto.CreatePropertyCondition( _\r\n                                          UIA_ControlTypePropertyId, _\r\n                                          UIA_TreeItemControlTypeId _\r\n                                        ))\r\n  If aryTreeItems.Length &lt; 1 Then Exit Sub\r\n  For i = 0 To aryTreeItems.Length - 1\r\n    If InStr(LCase(aryTreeItems.GetElement(i).CurrentName), LCase(ProjectName)) Then\r\n      Set ptnExpand = aryTreeItems.GetElement(i) _\r\n                      .GetCurrentPattern(UIA_ExpandCollapsePatternId)\r\n      If ExpandState = True Then\r\n        ptnExpand.Expand\r\n      Else\r\n        ptnExpand.Collapse\r\n      End If\r\n      Exit For\r\n    End If\r\n  Next\r\nEnd Sub\r\n\r\nPrivate Function GetElement(ByVal uiAuto As CUIAutomation, _\r\n                            ByVal elmParent As IUIAutomationElement, _\r\n                            ByVal propertyId As Long, _\r\n                            ByVal propertyValue As Variant, _\r\n                            Optional ByVal ctrlType As Long = 0) As IUIAutomationElement\r\n  Dim cndFirst As IUIAutomationCondition\r\n  Dim cndSecond As IUIAutomationCondition\r\n     \r\n  Set cndFirst = uiAuto.CreatePropertyCondition( _\r\n                   propertyId, _\r\n                   propertyValue _\r\n                 )\r\n  If ctrlType &lt;&gt; 0 Then\r\n    Set cndSecond = uiAuto.CreatePropertyCondition( _\r\n                      UIA_ControlTypePropertyId, _\r\n                      ctrlType _\r\n                    )\r\n    Set cndFirst = uiAuto.CreateAndCondition( _\r\n                     cndFirst, _\r\n                     cndSecond _\r\n                   )\r\n  End If\r\n  Set GetElement = elmParent.FindFirst(TreeScope_Subtree, cndFirst)\r\nEnd Function<\/pre>\n<p><a href=\"https:\/\/social.msdn.microsoft.com\/profile\/gekka\/?ws=usercard-mini\" title=\"gekka \u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\" target=\"_blank\">gekka<\/a>\u6c0f\u304c\u3059\u3067\u306b<a href=\"https:\/\/social.msdn.microsoft.com\/Forums\/ja-JP\/vbajp\/thread\/9dc9d029-cb6a-4e4d-9c81-3b899db899a0\" title=\"Excel2016 \uff62PERSONAL.XLSB\uff63VBA\u304b\u3089VBE\u3092\u64cd\u4f5c\u3059\u308b(\u958b\u304f)\" target=\"_blank\">\u30b9\u30ec\u30c3\u30c9<\/a>\u306b\u6319\u3052\u3089\u308c\u3066\u3044\u308b\u30b3\u30fc\u30c9\u3068\u307b\u307c\u540c\u3058\u5185\u5bb9\u3067\u3059\u304c\u3001Word\u3084PowerPoint\u3067\u3082\u52d5\u4f5c\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>ExpandVbaProject\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30fc\u306e\u7b2c\u4e00\u5f15\u6570\u3067\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u3092\u3001\u7b2c\u4e8c\u5f15\u6570\u3067\u5c55\u958b\u3059\u308b\u304b\u305f\u305f\u3080\u304b\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u308f\u3051\u3067\u3059\u304c\u3001\u4e0a\u3067\u66f8\u3044\u305f\u901a\u308a\u9700\u8981\u306f\u304b\u306a\u308a\u8b0e\u306a\u30de\u30af\u30ed\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<div id=\"single_banner_area2\" class=\"clearfix one_banner\">\n<div class=\"single_banner single_banner_left\">\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<!-- \u8a18\u4e8b\u4e2d(\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u5e83\u544a\u30e6\u30cb\u30c3\u30c8) -->\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-7306936664602087\"\r\n     data-ad-slot=\"5429724765\"\r\n     data-ad-format=\"auto\"\r\n     data-full-width-responsive=\"true\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\n<\/div>\n<div class=\"single_banner single_banner_right\">\n<a href=\"\" target=\"_blank\"><img decoding=\"async\" src=\"\" alt=\"\" title=\"\" \/><\/a>\n<\/div>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"MSDN\u30d5\u30a9\u30fc\u30e9\u30e0\u306b\u9762\u767d\u3044\u8cea\u554f\u304c\u3042\u308a\u307e\u3057\u305f\u3002 VBE\u30fb\u30d7\u30ed\u30b8\u30a7\u30af\u30c8 \u30a8\u30af\u30b9\u30d7\u30ed\u30fc\u30e9\u30fc\u306b\u3042\u308b\u6307\u5b9a\u3057\u305f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u30de\u30af\u30ed\u3067\u201c\u5c55\u958b\u201d\u3057\u305f\u3044(\u300c\uff0b\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af)\u3001\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002 \u30de\u30af\u30ed\u3067\u3053\u306e\u4f5c\u696d\u3092\u884c\u3046\u5fc5\u8981\u6027\u304c\u672c\u5f53\u306b\u3042\u308b [&hellip;]","protected":false},"author":1,"featured_media":7120,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"[VBA\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u300c\u5c55\u958b\u3059\u308b\u300dVBA\u30de\u30af\u30ed]","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-10042","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-OfficeVBA.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-2BY","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10042","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=10042"}],"version-history":[{"count":1,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10042\/revisions"}],"predecessor-version":[{"id":10043,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10042\/revisions\/10043"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7120"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}