{"id":1698,"date":"2012-05-16T17:50:16","date_gmt":"2012-05-16T08:50:16","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=1698"},"modified":"2012-05-20T15:41:57","modified_gmt":"2012-05-20T06:41:57","slug":"yahoo%e7%bf%bb%e8%a8%b3%e3%81%a7%e6%96%87%e5%ad%97%e5%88%97%e3%82%92%e7%bf%bb%e8%a8%b3%e3%81%99%e3%82%8b%e3%83%9e%e3%82%af%e3%83%ad","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=1698","title":{"rendered":"Yahoo!\u7ffb\u8a33\u3067\u6587\u5b57\u5217\u3092\u7ffb\u8a33\u3059\u308b\u30de\u30af\u30ed"},"content":{"rendered":"<p>\u300c<a href=\"\/\/www.ka-net.org\/blog\/?p=1274\" title=\"Google\u7ffb\u8a33\u3067\u6587\u5b57\u5217\u3092\u7ffb\u8a33\u3059\u308b\u30de\u30af\u30ed\" target=\"_blank\">Google\u7ffb\u8a33\u3067\u6587\u5b57\u5217\u3092\u7ffb\u8a33\u3059\u308b\u30de\u30af\u30ed<\/a>\u300d\u3067\u306fGoogle\u7ffb\u8a33\u3092\u5229\u7528\u3057\u305f\u30de\u30af\u30ed\u306b\u3064\u3044\u3066\u66f8\u304d\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306fGoogle\u3067\u306f\u306a\u304f<strong><a href=\"http:\/\/honyaku.yahoo.co.jp\/\" title=\"Yahoo!\u7ffb\u8a33\" target=\"_blank\">Yahoo!\u7ffb\u8a33<\/a><\/strong>\u3092\u5229\u7528\u3057\u305f\u30de\u30af\u30ed\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nPublic Sub Sample()\r\n  Dim target As String\r\n  Dim ret As String\r\n  \r\n  '\u30c6\u30b9\u30c8\u7528\u6587\u5b57\u5217\u306f http:\/\/ja.wikipedia.org\/wiki\/%E3%83%9E%E3%82%A4%E3%82%AF%E3%83%AD%E3%82%BD%E3%83%95%E3%83%88 \u3088\u308a\r\n  target = &quot;\u30de\u30a4\u30af\u30ed\u30bd\u30d5\u30c8\uff08Microsoft Corporation\uff09\u306f\u3001\u30a2\u30e1\u30ea\u30ab\u5408\u8846\u56fd\u306b\u672c\u793e\u3092\u7f6e\u304f\u4e16\u754c\u6700\u5927\u306e\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fb\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u4f1a\u793e\u3002&quot; &amp; vbCrLf\r\n  target = target &amp; &quot;\u73fe\u5728\u3067\u306f\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u4e8b\u696d\u3092\u624b\u304c\u3051\u3001\u30b9\u30de\u30fc\u30c8\u30d5\u30a9\u30f3\u3001\u30cf\u30fc\u30c9\u30a6\u30a7\u30a2\u3001\u30b2\u30fc\u30e0\u6a5f\u5668\u3082\u88fd\u9020\u3057\u3066\u3044\u308b\u3002&quot; &amp; vbCrLf\r\n  target = target &amp; &quot;1975\u5e744\u67084\u65e5\u306b\u30d3\u30eb\u30fb\u30b2\u30a4\u30c4\u3068\u30dd\u30fc\u30eb\u30fb\u30a2\u30ec\u30f3\u3089\u306b\u3088\u3063\u3066\u8a2d\u7acb\u3055\u308c\u305f\u3002&quot;\r\n  ret = TranslateYahoo(target, &quot;ja&quot;, &quot;zh&quot;) '\u65e5\u672c\u8a9e\u304b\u3089\u4e2d\u56fd\u8a9e\r\n  If Len(ret) &gt; 0 Then\r\n    CreateObject(&quot;WScript.Shell&quot;).Popup ret\r\n  End If\r\nEnd Sub\r\n\r\nPrivate Function TranslateYahoo(ByVal target As String, Optional ByVal FromLng As String = &quot;auto&quot;, Optional ByVal ToLng As String = &quot;en&quot;) As String\r\n  Dim dat As Variant\r\n  Dim js As String\r\n  Dim ret As String\r\n  Dim url As String\r\n  Dim crumb As String\r\n  Dim itm As Object\r\n  Dim cnt As Long\r\n  Dim ResultSet, ResultText, Results, key, TranslatedText '\u8868\u793a\u7528\u30c0\u30df\u30fc\r\n  \r\n  '********************************************************************\r\n  '\u25a0 \u5bfe\u5fdc\u3059\u308b\u8a00\u8a9e(\u5f15\u6570FromLng,ToLng) http:\/\/honyaku.yahoo.co.jp\/ \u3088\u308a\r\n  '   \u81ea\u52d5\u691c\u51fa:auto(FromLng\u306e\u307f)\r\n  '   \u65e5\u672c\u8a9e:ja\r\n  '   \u82f1\u8a9e:en\r\n  '   \u4e2d\u56fd\u8a9e:zh\r\n  '   \u97d3\u56fd\u8a9e:ko\r\n  '   \u30d5\u30e9\u30f3\u30b9\u8a9e:fr\r\n  '   \u30c9\u30a4\u30c4\u8a9e:de\r\n  '   \u30b9\u30da\u30a4\u30f3\u8a9e:es\r\n  '   \u30dd\u30eb\u30c8\u30ac\u30eb\u8a9e:pt\r\n  '   \u30a4\u30bf\u30ea\u30a2\u8a9e:it\r\n  '********************************************************************\r\n  \r\n  ret = &quot;&quot; '\u521d\u671f\u5316\r\n  '\u6587\u5b57\u6570\u30c1\u30a7\u30c3\u30af(4,000\u6587\u5b57\u307e\u3067)\r\n  If Len(target) &gt;= 4000 Then\r\n    MsgBox &quot;\u7ffb\u8a33\u5bfe\u8c61\u306e\u6587\u5b57\u6570\u304c\u591a\u904e\u304e\u307e\u3059\u3002&quot; &amp; vbCrLf &amp; &quot;\u7ffb\u8a33\u53ef\u80fd\u306a\u6587\u5b57\u6570\u306f4,000\u6587\u5b57\u307e\u3067\u3067\u3059\u3002&quot;, vbExclamation + vbSystemModal\r\n    GoTo Err:\r\n  End If\r\n  '\u5bfe\u5fdc\u8a00\u8a9e\u30c1\u30a7\u30c3\u30af\r\n  FromLng = LCase$(FromLng)\r\n  Select Case FromLng\r\n    Case &quot;auto&quot;\r\n      FromLng = GetPredictLanguage(target)\r\n      If Len(Trim$(FromLng)) &lt; 1 Then\r\n        MsgBox &quot;\u7ffb\u8a33\u5143\u8a00\u8a9e\u306e\u81ea\u52d5\u5224\u5b9a\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002&quot; &amp; vbCrLf &amp; &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, vbCritical + vbSystemModal\r\n        GoTo Err:\r\n      End If\r\n    Case &quot;en&quot;, &quot;zh&quot;, &quot;ko&quot;, &quot;fr&quot;, &quot;de&quot;, &quot;es&quot;, &quot;pt&quot;, &quot;it&quot;, &quot;ja&quot;\r\n    Case Else\r\n      MsgBox &quot;\u672a\u5bfe\u5fdc\u306e\u7ffb\u8a33\u5143\u8a00\u8a9e\u3067\u3059\u3002&quot;, vbCritical + vbSystemModal\r\n      GoTo Err:\r\n  End Select\r\n  ToLng = LCase$(ToLng)\r\n  Select Case ToLng\r\n    Case &quot;en&quot;, &quot;zh&quot;, &quot;ko&quot;, &quot;fr&quot;, &quot;de&quot;, &quot;es&quot;, &quot;pt&quot;, &quot;it&quot;, &quot;ja&quot;\r\n    Case Else\r\n      MsgBox &quot;\u672a\u5bfe\u5fdc\u306e\u7ffb\u8a33\u5148\u8a00\u8a9e\u3067\u3059\u3002&quot;, vbCritical + vbSystemModal\r\n      GoTo Err:\r\n  End Select\r\n  \r\n  crumb = &quot;&quot; '\u521d\u671f\u5316\r\n  crumb = GetCrumb()\r\n  If Len(Trim$(crumb)) &lt; 1 Then\r\n    MsgBox &quot;crumb\u306e\u53d6\u5f97\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002&quot; &amp; vbCrLf &amp; &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, vbCritical + vbSystemModal\r\n    GoTo Err:\r\n  End If\r\n  \r\n  js = &quot;&quot;: cnt = 1 '\u521d\u671f\u5316\r\n  url = &quot;http:\/\/honyaku.yahoo.co.jp\/TranslationText&quot;\r\n  dat = &quot;ieid=&quot; &amp; FromLng &amp; &quot;&amp;oeid=&quot; &amp; ToLng &amp; &quot;&amp;output=json&amp;_crumb=&quot; &amp; crumb &amp; &quot;&amp;p=&quot; &amp; EncodeURL(target)\r\n  On Error Resume Next\r\n  With CreateObject(&quot;MSXML2.XMLHTTP&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    If .Status = 200 Then js = .responseText\r\n  End With\r\n  On Error GoTo 0\r\n  If Len(js) &gt; 0 Then\r\n    js = &quot;(&quot; &amp; js &amp; &quot;)&quot;\r\n    With CreateObject(&quot;ScriptControl&quot;)\r\n      .Language = &quot;JScript&quot;\r\n      For Each itm In .CodeObject.eval(js).ResultSet.ResultText.Results\r\n        If cnt = 1 Then\r\n          ret = ret &amp; itm.TranslatedText\r\n        Else\r\n          ret = ret &amp; vbCrLf &amp; itm.TranslatedText\r\n        End If\r\n        cnt = cnt + 1\r\n      Next\r\n    End With\r\n  End If\r\n  \r\nErr:\r\n  TranslateYahoo = ret\r\nEnd Function\r\n\r\nPrivate Function GetCrumb() As String\r\n'TTcrumb\u306e\u5024\u53d6\u5f97\r\n  Dim ret As String\r\n  Dim crumb As String\r\n  Dim v As Variant\r\n  \r\n  crumb = &quot;&quot; '\u521d\u671f\u5316\r\n  On Error Resume Next\r\n  With CreateObject(&quot;MSXML2.XMLHTTP&quot;)\r\n    .Open &quot;GET&quot;, &quot;http:\/\/honyaku.yahoo.co.jp\/transtext\/&quot;, False\r\n    .Send\r\n    If .Status = 200 Then ret = .responseText\r\n  End With\r\n  On Error GoTo 0\r\n  If Len(ret) &gt; 0 Then\r\n    With CreateObject(&quot;VBScript.RegExp&quot;)\r\n      .IgnoreCase = True\r\n      .Global = True\r\n      .Pattern = &quot;id=&quot;&quot;TTcrumb&quot;&quot;.*(?=&quot;&quot;\/&gt;)&quot;\r\n      If .Test(ret) Then\r\n        v = Split(.Execute(ret)(0), &quot;&quot;&quot;&quot;)\r\n        crumb = v(UBound(v))\r\n      End If\r\n    End With\r\n  End If\r\n  GetCrumb = crumb\r\nEnd Function\r\n\r\nPrivate Function GetPredictLanguage(ByVal target As String)\r\n'\u8a00\u8a9e\u81ea\u52d5\u5224\u5b9a\u7d50\u679c\u53d6\u5f97\r\n  Dim d As Object\r\n  Dim ret As String\r\n  Dim url As String\r\n  \r\n  ret = &quot;&quot;: Set d = Nothing '\u521d\u671f\u5316\r\n  'url=&quot;http:\/\/honyaku.yahoo.co.jp\/LangClassifyService\/V1\/predict_prob?output=json&amp;query=&quot;\r\n  url = &quot;http:\/\/honyaku.yahoo.co.jp\/LangClassifyService\/V1\/predict_prob?query=&quot; &amp; EncodeURL(target)\r\n  On Error Resume Next\r\n  With CreateObject(&quot;MSXML2.XMLHTTP&quot;)\r\n    .Open &quot;GET&quot;, url, False\r\n    .setRequestHeader &quot;Content-Type&quot;, &quot;application\/x-www-form-urlencoded&quot;\r\n    .Send\r\n    If .Status = 200 Then Set d = .responseXML\r\n  End With\r\n  If Not d Is Nothing Then\r\n    ret = d.SelectSingleNode(&quot;\/ResultSet\/Predict&quot;).Text\r\n  End If\r\n  On Error GoTo 0\r\n  GetPredictLanguage = ret\r\nEnd Function\r\n\r\nPrivate Function EncodeURL(ByVal sWord As String) As String\r\n  With CreateObject(&quot;ScriptControl&quot;)\r\n    .Language = &quot;JScript&quot;\r\n    EncodeURL = .CodeObject.encodeURIComponent(sWord)\r\n  End With\r\nEnd Function<\/pre>\n<p>\u7ffb\u8a33\u5bfe\u8c61\u306e\u6587\u5b57\u5217\u3068\u5143\u306e\u8a00\u8a9e\u3001\u7ffb\u8a33\u3059\u308b\u8a00\u8a9e\u3092\u5f15\u6570\u3068\u3057\u3066\u6e21\u3059\u3068\u3001Yahoo!\u7ffb\u8a33\u3067\u7ffb\u8a33\u3057\u305f\u7d50\u679c\u3092\u8fd4\u3059\u30de\u30af\u30ed\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u300cGoogle\u7ffb\u8a33\u3067\u6587\u5b57\u5217\u3092\u7ffb\u8a33\u3059\u308b\u30de\u30af\u30ed\u300d\u3067\u306fGoogle\u7ffb\u8a33\u3092\u5229\u7528\u3057\u305f\u30de\u30af\u30ed\u306b\u3064\u3044\u3066\u66f8\u304d\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306fGoogle\u3067\u306f\u306a\u304fYahoo!\u7ffb\u8a33\u3092\u5229\u7528\u3057\u305f\u30de\u30af\u30ed\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002 Option Explicit Pub [&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,50],"tags":[8,11,35,62],"class_list":["post-1698","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-excel-office","category-word-office","category-translate","tag-vba","tag-office-2","tag-35","tag-yahoo"],"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-ro","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1698","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=1698"}],"version-history":[{"count":8,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1698\/revisions"}],"predecessor-version":[{"id":1710,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1698\/revisions\/1710"}],"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=1698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}