{"id":6743,"date":"2016-02-26T15:17:59","date_gmt":"2016-02-26T06:17:59","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=6743"},"modified":"2016-02-26T15:17:59","modified_gmt":"2016-02-26T06:17:59","slug":"google-charts-api%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6qr%e3%82%b3%e3%83%bc%e3%83%89%e3%81%ae%e7%94%bb%e5%83%8f%e3%82%92%e5%8f%96%e5%be%97%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=6743","title":{"rendered":"Google Charts API\u3092\u4f7f\u3063\u3066QR\u30b3\u30fc\u30c9\u306e\u753b\u50cf\u3092\u53d6\u5f97\u3059\u308bVBA\u30de\u30af\u30ed"},"content":{"rendered":"<p><a href=\"http:\/\/www.atmarkit.co.jp\/\" title=\"IT\u30a8\u30ad\u30b9\u30d1\u30fc\u30c8\u306e\u305f\u3081\u306e\u554f\u984c\u89e3\u6c7a\u30e1\u30c7\u30a3\u30a2 - \uff20IT\" target=\"_blank\">\uff20IT<\/a>\u306e\u8a18\u4e8b\u306b\u300c<a href=\"http:\/\/www.atmarkit.co.jp\/ait\/articles\/1602\/26\/news037.html\" title=\"Tech TIPS\uff1aGoogle Chart API\u3092\u4f7f\u3063\u3066QR\u30b3\u30fc\u30c9\u3092\u4f5c\u308b - \uff20IT\" target=\"_blank\">Tech TIPS\uff1aGoogle Chart API\u3092\u4f7f\u3063\u3066QR\u30b3\u30fc\u30c9\u3092\u4f5c\u308b<\/a>\u300d\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u3063\u305f\u306e\u3067\u3001VBA\u304b\u3089\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n(\u7d30\u304b\u3044\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306f\u4e0a\u8a18\u8a18\u4e8b\u53c2\u7167)<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nPublic Sub Sample()\r\n  Const png As String = &quot;C:\\Test\\MyQR.png&quot;\r\n  GetQRImage size:=200, _\r\n             data:=&quot;\u6f22\u5b57\u3072\u3089\u304c\u306a\u30ab\u30bf\u30ab\u30caabc&quot;, _\r\n             pngpath:=png, _\r\n             margin:=0\r\n  With CreateObject(&quot;Scripting.FileSystemObject&quot;)\r\n    If .FileExists(png) = True Then\r\n      If MsgBox(&quot;\u53d6\u5f97\u3057\u305f\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304d\u307e\u3059\u304b\uff1f&quot;, vbYesNo) = vbYes Then\r\n        CreateObject(&quot;Shell.Application&quot;).ShellExecute png\r\n      End If\r\n    End If\r\n  End With\r\nEnd Sub\r\n\r\nPrivate Sub GetQRImage(ByVal size As Long, _\r\n                       ByVal data As String, _\r\n                       ByVal pngpath As String, _\r\n                       Optional ByVal code As String = &quot;UTF-8&quot;, _\r\n                       Optional ByVal errlevel As String = &quot;L&quot;, _\r\n                       Optional ByVal margin As Long = 4)\r\n'Google Chart API\u3092\u4f7f\u3063\u3066QR\u30b3\u30fc\u30c9\u3092PNG\u753b\u50cf\u3068\u3057\u3066\u53d6\u5f97\r\n'\u203b URL\u30a8\u30f3\u30b3\u30fc\u30c9\u51e6\u7406\u306bScriptControl\u3092\u4f7f\u3063\u3066\u3044\u308b\u305f\u308132\u30d3\u30c3\u30c8\u7248Office\u306e\u307f\u5229\u7528\u53ef\u80fd\r\n'https:\/\/developers.google.com\/chart\/infographics\/docs\/qr_codes\r\n'https:\/\/google-developers.appspot.com\/chart\/infographics\/docs\/post_requests\r\n'http:\/\/www.atmarkit.co.jp\/ait\/articles\/1602\/26\/news037.html\r\n  Dim url As String\r\n  Dim body As Variant\r\n  Dim dat As Variant\r\n  Const adTypeBinary = 1\r\n  Const adSaveCreateOverWrite = 2\r\n  \r\n  url = &quot;https:\/\/chart.googleapis.com\/chart&quot;\r\n  dat = &quot;cht=qr&amp;chs=&quot; &amp; size &amp; &quot;x&quot; &amp; size &amp; _\r\n        &quot;&amp;chl=&quot; &amp; EncodeURL(data) &amp; _\r\n        &quot;&amp;choe=&quot; &amp; code &amp; _\r\n        &quot;&amp;chld=&quot; &amp; errlevel &amp; &quot;|&quot; &amp; margin\r\n  On Error Resume Next\r\n  With CreateObject(&quot;WinHttp.WinHttpRequest.5.1&quot;)\r\n    .Open &quot;POST&quot;, url, False\r\n    .SetRequestHeader &quot;Content-Type&quot;, &quot;application\/x-www-form-urlencoded; charset=UTF-8&quot;\r\n    .Send dat\r\n    Select Case .Status\r\n      Case 200\r\n        body = .ResponseBody\r\n        With CreateObject(&quot;ADODB.Stream&quot;)\r\n          .Type = adTypeBinary\r\n          .Open\r\n          .Write body\r\n          .SaveToFile pngpath, adSaveCreateOverWrite\r\n          .Close\r\n        End With\r\n    End Select\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; vbNewLine &amp; _\r\n           &quot;\u30a8\u30e9\u30fc\u5185\u5bb9\uff1a&quot; &amp; Err.Description, _\r\n           vbCritical + vbSystemModal, _\r\n           &quot;\u30a8\u30e9\u30fc\u756a\u53f7\uff1a&quot; &amp; Err.Number\r\n  End If\r\n  On Error GoTo 0\r\nEnd Sub\r\n\r\nPrivate Function EncodeURL(ByVal str As String) As String\r\n  With CreateObject(&quot;ScriptControl&quot;)\r\n    .Language = &quot;JScript&quot;\r\n    EncodeURL = .CodeObject.encodeURIComponent(str)\r\n  End With\r\nEnd Function<\/pre>\n<p>\uff20IT\u306e\u8a18\u4e8b\u3068\u9055\u3063\u3066POST\u3067\u51e6\u7406\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u3084\u308a\u65b9\u306f\u540c\u3058\u3067\u3059\u3002<br \/>\n\u7c21\u5358\u306bQR\u753b\u50cf\u3092\u53d6\u5f97\u3067\u304d\u308b\u306e\u3067\u3001\u306a\u304b\u306a\u304b\u4fbf\u5229\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\uff20IT\u306e\u8a18\u4e8b\u306b\u300cTech TIPS\uff1aGoogle Chart API\u3092\u4f7f\u3063\u3066QR\u30b3\u30fc\u30c9\u3092\u4f5c\u308b\u300d\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u3063\u305f\u306e\u3067\u3001VBA\u304b\u3089\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u305f\u3002 (\u7d30\u304b\u3044\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306f\u4e0a\u8a18\u8a18\u4e8b\u53c2\u7167) Option Explicit P [&hellip;]","protected":false},"author":1,"featured_media":7111,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"[Google Charts API\u3092\u4f7f\u3063\u3066QR\u30b3\u30fc\u30c9\u306e\u753b\u50cf\u3092\u53d6\u5f97\u3059\u308bVBA\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,126],"tags":[],"class_list":["post-6743","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-excel-office","category-word-office","category-powerpoint","category-google"],"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-1KL","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6743","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=6743"}],"version-history":[{"count":1,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6743\/revisions"}],"predecessor-version":[{"id":6744,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6743\/revisions\/6744"}],"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=6743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}