{"id":207,"date":"2011-08-21T12:11:20","date_gmt":"2011-08-21T03:11:20","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=207"},"modified":"2011-08-21T12:12:40","modified_gmt":"2011-08-21T03:12:40","slug":"menu%e5%86%85%e3%81%ab%e3%81%82%e3%82%8bbutton%e3%81%ae%e6%95%b0%e3%82%92%e5%a2%97%e3%82%84%e3%81%99","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=207","title":{"rendered":"menu\u5185\u306b\u3042\u308bbutton\u306e\u6570\u3092\u5897\u3084\u3059"},"content":{"rendered":"<p>\u300c<a href=\"\/\/www.ka-net.org\/blog\/?p=196\" title=\"\u5916\u90e8\u306eXML\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u306b\u5fdc\u3058\u3066menu\u5185\u5bb9\u3092\u5909\u66f4\u3059\u308b\" target=\"_blank\">\u5916\u90e8\u306eXML\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u306b\u5fdc\u3058\u3066menu\u5185\u5bb9\u3092\u5909\u66f4\u3059\u308b<\/a>\u300d\u306e\u95a2\u9023\u3067\u3001<span style=\"color: #ff0000;\">dynamicMenu<\/span>\u8981\u7d20\u306e<span style=\"color: #ff0000;\">getContent<\/span>\u5c5e\u6027\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u5229\u7528\u3057\u3066menu\u5185\u306b\u3042\u308bbutton\u306e\u6570\u3092\u5897\u3084\u3059\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<br \/>\n<!--more--><\/p>\n<p><strong>[\u30ea\u30dc\u30f3XML]<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\r\n&lt;customUI onLoad=&quot;rbnSample_onLoad&quot; xmlns=&quot;http:\/\/schemas.microsoft.com\/office\/2006\/01\/customui&quot;&gt;\r\n  &lt;ribbon&gt;\r\n    &lt;tabs&gt;\r\n      &lt;tab id=&quot;tabSample&quot; label=&quot;Sample Tab&quot;&gt;\r\n        &lt;group id=&quot;grpSample&quot; label=&quot;Sample Group&quot;&gt;\r\n          &lt;button id=&quot;btnSample&quot; label=&quot;Button\u5897\u52a0&quot; size=&quot;large&quot; imageMso=&quot;PlusSign&quot; onAction=&quot;btnSample_onAction&quot; \/&gt;\r\n          &lt;dynamicMenu id=&quot;dmuSample&quot; label=&quot;Sample Menu&quot; size=&quot;large&quot; imageMso=&quot;HappyFace&quot; getContent=&quot;dmuSample_getContent&quot; \/&gt;\r\n        &lt;\/group&gt;\r\n      &lt;\/tab&gt;\r\n    &lt;\/tabs&gt;\r\n  &lt;\/ribbon&gt;\r\n&lt;\/customUI&gt;<\/pre>\n<p><strong>[\u6a19\u6e96\u30e2\u30b8\u30e5\u30fc\u30eb]<\/strong><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nPrivate myRibbon As Office.IRibbonUI\r\n\r\nPrivate Sub rbnSample_onLoad(ribbon As IRibbonUI)\r\n  Set myRibbon = ribbon\r\nEnd Sub\r\n\r\nPrivate Sub btnSample_onAction(control As IRibbonControl)\r\n  IncButtonElement ThisWorkbook.Path &amp; &quot;\\Sample.xml&quot;, &quot;btnSample&quot;, &quot;Sample Button&quot;\r\n  myRibbon.InvalidateControl &quot;dmuSample&quot;\r\nEnd Sub\r\n\r\nPrivate Sub dmuSample_getContent(control As IRibbonControl, ByRef returnedVal)\r\n  Dim MenuXML As String\r\n  \r\n  MenuXML = LoadMenuFile(ThisWorkbook.Path &amp; &quot;\\Sample.xml&quot;)\r\n  If Len(Trim$(MenuXML)) &lt; 1 Then Exit Sub\r\n  returnedVal = MenuXML\r\nEnd Sub\r\n\r\nPrivate Function LoadMenuFile(ByVal FilePath As String) As String\r\n  Dim ret As String\r\n  \r\n  ret = &quot;&quot; '\u521d\u671f\u5316\r\n  On Error Resume Next\r\n  With CreateObject(&quot;Msxml2.DOMDocument&quot;)\r\n    .async = False\r\n    If .Load(FilePath) Then ret = .XML\r\n  End With\r\n  On Error GoTo 0\r\n  LoadMenuFile = ret\r\nEnd Function\r\n\r\nPrivate Sub IncButtonElement(ByVal XmlFilePath As String, ByVal BtnID As String, ByVal BtnLabel As String)\r\n'button\u8981\u7d20\u5897\u52a0\r\n  Dim d As Object\r\n  Dim n As Object\r\n  Dim cnt As Long\r\n  \r\n  Set d = CreateObject(&quot;Msxml2.DOMDocument&quot;)\r\n  d.async = False\r\n  If d.Load(XmlFilePath) Then\r\n    cnt = d.getElementsByTagName(&quot;button&quot;).Length\r\n    '&#x5B;xmlns=&quot;&quot;]\u304c\u8ffd\u52a0\u3055\u308c\u308b\u306e\u3092\u9632\u3050\u305f\u3081\u306b\u540d\u524d\u7a7a\u9593URI\u8a2d\u5b9a\r\n    Set n = d.createNode(1, &quot;button&quot;, d.DocumentElement.NamespaceURI)\r\n    With d.DocumentElement.appendChild(n)\r\n      .setAttribute &quot;id&quot;, BtnID &amp; cnt + 1\r\n      .setAttribute &quot;label&quot;, BtnLabel &amp; cnt + 1\r\n      .setAttribute &quot;imageMso&quot;, &quot;HappyFace&quot;\r\n    End With\r\n    Set n = Nothing\r\n    d.Save XmlFilePath\r\n  End If\r\n  Set d = Nothing\r\nEnd Sub<\/pre>\n<p>\u4e0a\u8a18\u30b3\u30fc\u30c9\u3092\u8a2d\u5b9a\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3068\u540c\u3058\u5834\u6240\u306b\u3001\u4e0b\u8a18XML\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<p><strong>[Sample.xml]<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;menu xmlns=&quot;http:\/\/schemas.microsoft.com\/office\/2006\/01\/customui&quot; itemSize=&quot;large&quot;&gt;\r\n  &lt;button id=&quot;btnSample1&quot; label=&quot;Sample Button1&quot; imageMso=&quot;HappyFace&quot;\/&gt;\r\n&lt;\/menu&gt;<\/pre>\n<p>XML\u30d5\u30a1\u30a4\u30eb\u4fdd\u5b58\u5f8c\u3001\u30ea\u30dc\u30f3\u30fb\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\u3068\u300c<strong>Sample Tab<\/strong>\u300d\u30bf\u30d6\u304c\u4e0b\u56f3\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/IncButtonElement01.jpg\" alt=\"\" title=\"IncButtonElement01\" width=\"262\" height=\"189\" class=\"alignnone size-full wp-image-210\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/IncButtonElement01.jpg 262w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/IncButtonElement01-150x108.jpg 150w\" sizes=\"auto, (max-width: 262px) 100vw, 262px\" \/><\/p>\n<p>\u300c<strong>Button\u5897\u52a0<\/strong>\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3053\u3068\u3067\u3001\u300c<strong>Sample Menu<\/strong>\u300d\u5185\u306b\u3042\u308bbutton\u306e\u6570\u3092\u5897\u3084\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/IncButtonElement02.jpg\" alt=\"\" title=\"IncButtonElement02\" width=\"262\" height=\"270\" class=\"alignnone size-full wp-image-211\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/IncButtonElement02.jpg 262w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/IncButtonElement02-145x150.jpg 145w\" sizes=\"auto, (max-width: 262px) 100vw, 262px\" \/><\/p>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306b\u3001menu\u5185\u5bb9\u3092\u5916\u90e8\u306eXML\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8aad\u307f\u8fbc\u3080\u3088\u3046\u306b\u3057\u3066\u3001\u30de\u30af\u30ed\u3067XML\u30d5\u30a1\u30a4\u30eb\u3092\u66f8\u304d\u63db\u3048\u305f\u5f8c\u306b\u518d\u5ea6XML\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u3088\u3046\u306b\u3059\u308c\u3070\u3001\u52d5\u7684\u306b\u30ea\u30dc\u30f3(\u306e\u4e00\u90e8)\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u300c\u5916\u90e8\u306eXML\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u306b\u5fdc\u3058\u3066menu\u5185\u5bb9\u3092\u5909\u66f4\u3059\u308b\u300d\u306e\u95a2\u9023\u3067\u3001dynamicMenu\u8981\u7d20\u306egetContent\u5c5e\u6027\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u5229\u7528\u3057\u3066menu\u5185\u306b\u3042\u308bbutton\u306e\u6570\u3092\u5897\u3084\u3059\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002","protected":false},"author":1,"featured_media":7130,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[12,7,11],"class_list":["post-207","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ribbon","tag-12","tag-ribbon-2","tag-office-2"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Ribbon.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-3l","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/207","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=207"}],"version-history":[{"count":8,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/207\/revisions"}],"predecessor-version":[{"id":217,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/207\/revisions\/217"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7130"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}