{"id":4479,"date":"2014-05-30T11:13:02","date_gmt":"2014-05-30T02:13:02","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=4479"},"modified":"2014-05-30T11:13:02","modified_gmt":"2014-05-30T02:13:02","slug":"%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92base64%e3%82%a8%e3%83%b3%e3%82%b3%e3%83%bc%e3%83%89%e3%83%bb%e3%83%87%e3%82%b3%e3%83%bc%e3%83%89%e3%81%99%e3%82%8bvba%e3%83%9e%e3%82%af%e3%83%ad","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=4479","title":{"rendered":"\u30d5\u30a1\u30a4\u30eb\u3092Base64\u30a8\u30f3\u30b3\u30fc\u30c9\u30fb\u30c7\u30b3\u30fc\u30c9\u3059\u308bVBA\u30de\u30af\u30ed"},"content":{"rendered":"<p>\u4ee5\u524d\u66f8\u3044\u305f\u30d5\u30a1\u30a4\u30eb\u306eBase64\u30a8\u30f3\u30b3\u30fc\u30c9\u30fb\u30c7\u30b3\u30fc\u30c9\u51e6\u7406\u3092\u884c\u3046VBA\u30de\u30af\u30ed\u3092\u30e1\u30e2\u3068\u3057\u3066\u6b8b\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nPublic Sub Sample()\r\n  Sheet1.TextBox1.Text = EncodeBase64(&quot;C:\\Test\\Sample.pdf&quot;)\r\n  Debug.Print DecodeBase64(Sheet1.TextBox1.Text, &quot;C:\\Test\\Sample_Decode.pdf&quot;)\r\nEnd Sub\r\n\r\nPrivate Function EncodeBase64(ByVal FilePath As String) As String\r\n'\u30d5\u30a1\u30a4\u30eb\u3092Base64\u30a8\u30f3\u30b3\u30fc\u30c9\r\n  Dim elm As Object\r\n  Dim ret As String\r\n  Const adTypeBinary = 1\r\n  Const adReadAll = -1\r\n  \r\n  ret = &quot;&quot; '\u521d\u671f\u5316\r\n  On Error Resume Next\r\n  Set elm = CreateObject(&quot;MSXML2.DOMDocument&quot;).createElement(&quot;base64&quot;)\r\n  With CreateObject(&quot;ADODB.Stream&quot;)\r\n    .Type = adTypeBinary\r\n    .Open\r\n    .LoadFromFile FilePath\r\n    elm.DataType = &quot;bin.base64&quot;\r\n    elm.nodeTypedValue = .Read(adReadAll)\r\n    ret = elm.Text\r\n    .Close\r\n  End With\r\n  On Error GoTo 0\r\n  EncodeBase64 = ret\r\nEnd Function\r\n\r\nPrivate Function DecodeBase64(ByVal Base64Str As String, ByVal FilePath As String) As Long\r\n'\u30d5\u30a1\u30a4\u30eb\u3092Base64\u30c7\u30b3\u30fc\u30c9\r\n  Dim elm As Object\r\n  Dim ret As Long\r\n  Const adTypeBinary = 1\r\n  Const adSaveCreateOverWrite = 2\r\n  \r\n  ret = -1 '\u521d\u671f\u5316\r\n  On Error Resume Next\r\n  Set elm = CreateObject(&quot;MSXML2.DOMDocument&quot;).createElement(&quot;base64&quot;)\r\n  elm.DataType = &quot;bin.base64&quot;\r\n  elm.Text = Base64Str\r\n  With CreateObject(&quot;ADODB.Stream&quot;)\r\n    .Type = adTypeBinary\r\n    .Open\r\n    .Write elm.nodeTypedValue\r\n    .SaveToFile FilePath, adSaveCreateOverWrite\r\n    .Close\r\n  End With\r\n  If Err.Number &lt;&gt; 0 Then ret = 0\r\n  On Error GoTo 0\r\n  DecodeBase64 = ret\r\nEnd Function<\/pre>\n<p>\u4e0a\u8a18\u306e\u901a\u308a\u3001\u30a8\u30e9\u30fc\u51e6\u7406\u306f\u9069\u5f53\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4ee5\u524d\u66f8\u3044\u305f\u30d5\u30a1\u30a4\u30eb\u306eBase64\u30a8\u30f3\u30b3\u30fc\u30c9\u30fb\u30c7\u30b3\u30fc\u30c9\u51e6\u7406\u3092\u884c\u3046VBA\u30de\u30af\u30ed\u3092\u30e1\u30e2\u3068\u3057\u3066\u6b8b\u3057\u3066\u304a\u304d\u307e\u3059\u3002 Option Explicit Public Sub Sample() Sheet1.TextBox1.Text = [&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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,48,49],"tags":[],"class_list":["post-4479","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-excel-office","category-word-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-1af","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4479","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=4479"}],"version-history":[{"count":1,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4479\/revisions"}],"predecessor-version":[{"id":4480,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4479\/revisions\/4480"}],"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=4479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}