{"id":5079,"date":"2014-11-21T14:51:35","date_gmt":"2014-11-21T05:51:35","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=5079"},"modified":"2014-11-21T14:51:35","modified_gmt":"2014-11-21T05:51:35","slug":"%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e3%83%96%e3%83%83%e3%82%af%e3%81%ab%e5%9f%8b%e3%82%81%e8%be%bc%e3%82%80excel%e3%83%9e%e3%82%af%e3%83%ad","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=5079","title":{"rendered":"\u30d5\u30a1\u30a4\u30eb\u3092\u30d6\u30c3\u30af\u306b\u57cb\u3081\u8fbc\u3080Excel\u30de\u30af\u30ed"},"content":{"rendered":"<p>\u5927\u5206\u524d\u306b\u66f8\u3044\u305f\u56de\u7b54\u7528\u306e\u30b3\u30fc\u30c9\u304c\u51fa\u3066\u304d\u305f\u306e\u3067\u3001\u8a18\u4e8b\u3068\u3057\u3066\u6b8b\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\n\u30d0\u30a4\u30ca\u30ea\u30d5\u30a1\u30a4\u30eb\u3092Base64\u30a8\u30f3\u30b3\u30fc\u30c9\u3057\u3001\u6587\u5b57\u5217\u3068\u3057\u3066\u30d6\u30c3\u30af\u5185\u306e<a href=\"http:\/\/msdn.microsoft.com\/ja-jp\/library\/ff863497.aspx\" title=\"CustomXMLPart \u30aa\u30d6\u30b8\u30a7\u30af\u30c8 (Office)\" target=\"_blank\">\u30ab\u30b9\u30bf\u30e0XML<\/a>\u306b\u683c\u7d0d\u3001\u307e\u305f\u683c\u7d0d\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u5143\u306e\u5f62\u5f0f\u3067\u53d6\u308a\u51fa\u3059Excel\u30de\u30af\u30ed\u3067\u3059\u3002<\/p>\n<p><span style=\"color: #ff0000; font-weight: bold;\">\u203b \u4e0b\u8a18\u30b3\u30fc\u30c9\u306fExcel 2007\u4ee5\u4e0a\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nPublic Sub Sample1()\r\n  FileToCustomXML ActiveWorkbook, &quot;obj1&quot;, &quot;C:\\Test\\Sample.pdf&quot;\r\n  FileToCustomXML ActiveWorkbook, &quot;obj2&quot;, &quot;C:\\Test\\Sample.png&quot;\r\n  MsgBox &quot;\u51e6\u7406\u304c\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002&quot;, vbInformation + vbSystemModal\r\nEnd Sub\r\n\r\nPublic Sub Sample2()\r\n  CustomXMLToFile ActiveWorkbook, &quot;obj1&quot;, &quot;C:\\Test\\SampleR.pdf&quot;\r\n  CustomXMLToFile ActiveWorkbook, &quot;obj2&quot;, &quot;C:\\Test\\SampleR.png&quot;\r\n  MsgBox &quot;\u51e6\u7406\u304c\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002&quot;, vbInformation + vbSystemModal\r\nEnd Sub\r\n\r\nPrivate Sub FileToCustomXML(ByRef TargetWorkbook As Workbook, _\r\n                            ByVal id As String, _\r\n                            ByVal FilePath As String)\r\n'\u30d5\u30a1\u30a4\u30eb\u3092Base64\u30a8\u30f3\u30b3\u30fc\u30c9\u3057\u3066\u30ab\u30b9\u30bf\u30e0XML\u306b\u683c\u7d0d\r\n  Dim d As Object\r\n  Dim elm As Object\r\n  Const adTypeBinary As Long = 1\r\n  Const adReadAll As Long = -1\r\n  Const ns As String = &quot;http:\/\/hoge.jp\/base64\/contents\/&quot; '\u9069\u5f53\u306a\u540d\u524d\u7a7a\u9593\r\n  \r\n  If Len(Dir$(FilePath)) &lt; 1&amp; Then\r\n    MsgBox &quot;\u5165\u529b\u5143\u30d5\u30a1\u30a4\u30eb&#x5B;&quot; &amp; FilePath &amp; &quot;]\u304c\u5b58\u5728\u3057\u3066\u3044\u307e\u305b\u3093\u3002&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, vbExclamation + vbSystemModal\r\n    Exit Sub\r\n  End If\r\n  If TargetWorkbook.CustomXMLParts.SelectByNamespace(ns &amp; id).Count &gt; 0&amp; Then\r\n    MsgBox TargetWorkbook.Name &amp; &quot;\u306b\u306f\u3059\u3067\u306b&#x5B;&quot; &amp; id &amp; &quot;]\u304c\u5b58\u5728\u3057\u3066\u3044\u307e\u3059\u3002&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, vbExclamation + vbSystemModal\r\n    Exit Sub\r\n  End If\r\n  On Error Resume Next\r\n  Set d = CreateObject(&quot;MSXML2.DOMDocument&quot;)\r\n  Set elm = d.createElement(&quot;base64&quot;)\r\n  elm.setAttribute &quot;xmlns&quot;, ns &amp; id '\u8b58\u5225\u7528ID\u4ed8\u52a0\r\n  elm.DataType = &quot;bin.base64&quot;\r\n  With CreateObject(&quot;ADODB.Stream&quot;)\r\n    .Type = adTypeBinary\r\n    .Open\r\n    .LoadFromFile FilePath\r\n    elm.nodeTypedValue = .Read(adReadAll)\r\n    .Close\r\n  End With\r\n  d.appendChild elm\r\n  TargetWorkbook.CustomXMLParts.Add d.XML\r\n  If Err.Number &lt;&gt; 0 Then\r\n    MsgBox &quot;\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u30a8\u30e9\u30fc\u5185\u5bb9:&quot; &amp; Err.Description, vbCritical + vbSystemModal\r\n  End If\r\n  On Error GoTo 0\r\nEnd Sub\r\n\r\nPrivate Sub CustomXMLToFile(ByVal TargetWorkbook As Workbook, _\r\n                            ByVal id As String, _\r\n                            ByVal FilePath As String)\r\n'\u30d5\u30a1\u30a4\u30eb\u304c\u683c\u7d0d\u3055\u308c\u305f\u30ab\u30b9\u30bf\u30e0XML\u304b\u3089Base64\u30c7\u30b3\u30fc\u30c9\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u3092\u51fa\u529b\r\n  Dim d As Object\r\n  Const adTypeBinary As Long = 1\r\n  Const ns As String = &quot;http:\/\/hoge.jp\/base64\/contents\/&quot; '\u9069\u5f53\u306a\u540d\u524d\u7a7a\u9593\r\n  \r\n  If Len(Dir$(FilePath)) &gt; 0&amp; Then\r\n    MsgBox &quot;\u51fa\u529b\u5148\u30d5\u30a1\u30a4\u30eb&#x5B;&quot; &amp; FilePath &amp; &quot;]\u304c\u3059\u3067\u306b\u5b58\u5728\u3057\u3066\u3044\u307e\u3059\u3002&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, vbExclamation + vbSystemModal\r\n    Exit Sub\r\n  End If\r\n  If TargetWorkbook.CustomXMLParts.SelectByNamespace(ns &amp; id).Count &lt; 1&amp; Then\r\n    MsgBox TargetWorkbook.Name &amp; &quot;\u306b\u306f&#x5B;&quot; &amp; id &amp; &quot;]\u304c\u5b58\u5728\u3057\u3066\u3044\u307e\u305b\u3093\u3002&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, vbExclamation + vbSystemModal\r\n    Exit Sub\r\n  End If\r\n  On Error Resume Next\r\n  Set d = CreateObject(&quot;MSXML2.DOMDocument&quot;)\r\n  With CreateObject(&quot;ADODB.Stream&quot;)\r\n    .Type = adTypeBinary\r\n    .Open\r\n    d.LoadXML TargetWorkbook.CustomXMLParts.SelectByNamespace(ns &amp; id)(1).XML\r\n    .Write d.FirstChild.nodeTypedValue\r\n    .SaveToFile FilePath\r\n    .Close\r\n  End With\r\n  If Err.Number &lt;&gt; 0 Then\r\n    MsgBox &quot;\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u30a8\u30e9\u30fc\u5185\u5bb9:&quot; &amp; Err.Description, vbCritical + vbSystemModal\r\n  End If\r\n  On Error GoTo 0\r\nEnd Sub<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u30d6\u30c3\u30af\u306b\u57cb\u3081\u8fbc\u3080\u65b9\u6cd5\u3068\u3057\u3066\u3001<a href=\"http:\/\/office.microsoft.com\/ja-jp\/HP010217697.aspx\" title=\"OLE \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3001\u7de8\u96c6\u3001\u304a\u3088\u3073\u5236\u5fa1\u3059\u308b\" target=\"_blank\">OLE \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/a>\u3092\u5229\u7528\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u500b\u4eba\u7684\u306b\u306f\u6c4e\u7528\u7684\u306aBase64\u5f62\u5f0f\u306e\u65b9\u304c\u6271\u3044\u3084\u3059\u3044\u3088\u3046\u306b\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5927\u5206\u524d\u306b\u66f8\u3044\u305f\u56de\u7b54\u7528\u306e\u30b3\u30fc\u30c9\u304c\u51fa\u3066\u304d\u305f\u306e\u3067\u3001\u8a18\u4e8b\u3068\u3057\u3066\u6b8b\u3057\u3066\u304a\u304d\u307e\u3059\u3002 \u30d0\u30a4\u30ca\u30ea\u30d5\u30a1\u30a4\u30eb\u3092Base64\u30a8\u30f3\u30b3\u30fc\u30c9\u3057\u3001\u6587\u5b57\u5217\u3068\u3057\u3066\u30d6\u30c3\u30af\u5185\u306e\u30ab\u30b9\u30bf\u30e0XML\u306b\u683c\u7d0d\u3001\u307e\u305f\u683c\u7d0d\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u5143\u306e\u5f62\u5f0f\u3067\u53d6\u308a\u51fa\u3059Excel\u30de\u30af\u30ed\u3067\u3059 [&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":"","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],"tags":[],"class_list":["post-5079","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-excel-office"],"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-1jV","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5079","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=5079"}],"version-history":[{"count":1,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5079\/revisions"}],"predecessor-version":[{"id":5080,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5079\/revisions\/5080"}],"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=5079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}