{"id":1558,"date":"2012-03-29T14:53:18","date_gmt":"2012-03-29T05:53:18","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=1558"},"modified":"2012-09-05T16:46:41","modified_gmt":"2012-09-05T07:46:41","slug":"%e6%96%87%e6%9b%b8%e5%86%85%e3%81%ae%e5%8d%98%e8%aa%9e%e3%82%92%e5%8d%98%e8%aa%9e%e3%81%94%e3%81%a8%e3%81%ab%e3%82%ab%e3%82%a6%e3%83%b3%e3%83%88%e3%81%99%e3%82%8bword%e3%83%9e%e3%82%af%e3%83%ad","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=1558","title":{"rendered":"\u6587\u66f8\u5185\u306e\u5358\u8a9e\u3092\u5358\u8a9e\u3054\u3068\u306b\u30ab\u30a6\u30f3\u30c8\u3059\u308bWord\u30de\u30af\u30ed"},"content":{"rendered":"<p>Words\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u4f7f\u3063\u3066\u6587\u66f8\u5185\u306e\u5358\u8a9e\u3092\u5217\u6319\u3057\u3001\u5404\u5358\u8a9e\u304c\u305d\u308c\u305e\u308c\u3044\u304f\u3064\u3042\u308b\u306e\u304b\u3092\u30ab\u30a6\u30f3\u30c8\u3059\u308bWord\u30de\u30af\u30ed\u3067\u3001\u7d50\u679c\u306f\u65b0\u3057\u3044\u6587\u66f8\u306b\u8868\u5f62\u5f0f\u3067\u51fa\u529b\u3057\u307e\u3059\u3002<\/p>\n<p>\u30ab\u30a6\u30f3\u30c8\u3092\u884c\u3046\u300c<span style=\"color: #ff0000; font-weight: bold;\">CntWord<\/span>\u300d\u95a2\u6570\u5185\u306e\u691c\u7d22\u6761\u4ef6\u3092\u5909\u66f4\u3059\u308c\u3070\u5f97\u3089\u308c\u308b\u7d50\u679c\u3082\u5909\u66f4\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nPublic Sub CountDocumentWords()\r\n'\u6587\u66f8\u5185\u306e\u5358\u8a9e\u3092\u5358\u8a9e\u3054\u3068\u306b\u30ab\u30a6\u30f3\u30c8\u3059\u308b\r\n  Dim doc As Word.Document\r\n  Dim w As Word.Range\r\n  Dim dic As Object\r\n  Dim itm As Variant\r\n  Dim i As Long\r\n  \r\n  i = 2 '\u521d\u671f\u5316\r\n  Application.ScreenUpdating = False\r\n  Set doc = ActiveDocument\r\n  Set dic = CreateObject(&quot;Scripting.Dictionary&quot;)\r\n  For Each w In doc.Words\r\n    '\u5358\u8a9e\u304c\u91cd\u8907\u3057\u306a\u3044\u3088\u3046\u306bDictionary\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u7528\r\n    If Not dic.Exists(w.Text) Then\r\n      dic.Add w.Text, w.Text\r\n    End If\r\n  Next\r\n  With Application.Documents.Add\r\n    With .Tables.Add(.Range, 1, 3)\r\n      .Cell(1, 1).Range.Text = &quot;&quot;\r\n      .Cell(1, 2).Range.Text = &quot;\u5358\u8a9e&quot;\r\n      .Cell(1, 3).Range.Text = &quot;\u500b\u6570&quot;\r\n      For Each itm In dic.Items\r\n        .Rows.Add\r\n        .Cell(i, 1).Range.Text = i - 1\r\n        .Cell(i, 2).Range.Text = itm\r\n        .Cell(i, 3).Range.Text = CntWord(doc, itm)\r\n        i = i + 1\r\n      Next\r\n      '\u30c6\u30fc\u30d6\u30eb\u306e\u88c5\u98fe\r\n      .AutoFitBehavior wdAutoFitContent\r\n      .Borders.InsideLineStyle = wdLineStyleSingle\r\n      .Borders.OutsideLineStyle = wdLineStyleSingle\r\n      .Rows(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter\r\n      With .Rows(1).Shading\r\n        .Texture = wdTextureNone\r\n        .ForegroundPatternColor = wdColorAutomatic\r\n        .BackgroundPatternColor = 16751103\r\n      End With\r\n    End With\r\n  End With\r\n  Set dic = Nothing\r\n  Set doc = Nothing\r\n  Application.ScreenUpdating = True\r\n  MsgBox &quot;\u51e6\u7406\u304c\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002&quot;, vbInformation + vbSystemModal\r\nEnd Sub\r\n\r\nPrivate Function CntWord(ByVal doc As Word.Document, ByVal txt As String) As String\r\n'\u5358\u8a9e\u6570\u3092\u30ab\u30a6\u30f3\u30c8\u3059\u308b\r\n  Dim tmp As String\r\n  Dim ret As String\r\n  Dim r As Word.Range\r\n  Dim cnt As Long\r\n  \r\n  ret = &quot;&quot;: cnt = 0 '\u521d\u671f\u5316\r\n  tmp = Replace$(txt, &quot;\u3000&quot;, &quot;&quot;)\r\n  tmp = Replace$(tmp, &quot; &quot;, &quot;&quot;)\r\n  tmp = Replace$(tmp, vbCrLf, &quot;&quot;)\r\n  tmp = Replace$(tmp, vbCr, &quot;&quot;)\r\n  tmp = Replace$(tmp, vbLf, &quot;&quot;)\r\n  If Len(tmp) &gt; 0 Then\r\n    Set r = doc.Range(0, 0)\r\n    With r.Find\r\n      '\u691c\u7d22\u6761\u4ef6\u306f\u9069\u5b9c\u5909\u66f4\r\n      .ClearFormatting\r\n      .ClearAllFuzzyOptions\r\n      .Text = txt\r\n      .Replacement.Text = &quot;&quot;\r\n      .Forward = True\r\n      .Wrap = wdFindStop\r\n      .Format = False\r\n      .MatchCase = True\r\n      .MatchWholeWord = True\r\n      .MatchByte = False\r\n      .MatchAllWordForms = False\r\n      .MatchSoundsLike = False\r\n      .MatchWildcards = False\r\n      .MatchFuzzy = False\r\n      Do While .Execute\r\n        cnt = cnt + 1\r\n      Loop\r\n    End With\r\n    Set r = Nothing\r\n    ret = CStr(cnt)\r\n  End If\r\n  CntWord = ret\r\nEnd Function<\/pre>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/CountDocumentWords_01.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/CountDocumentWords_01-300x242.jpg\" alt=\"\" title=\"CountDocumentWords_01\" width=\"300\" height=\"242\" class=\"alignnone size-medium wp-image-1559\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/CountDocumentWords_01-300x242.jpg 300w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/CountDocumentWords_01-290x234.jpg 290w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/CountDocumentWords_01-150x121.jpg 150w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/CountDocumentWords_01.jpg 691w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"Words\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u4f7f\u3063\u3066\u6587\u66f8\u5185\u306e\u5358\u8a9e\u3092\u5217\u6319\u3057\u3001\u5404\u5358\u8a9e\u304c\u305d\u308c\u305e\u308c\u3044\u304f\u3064\u3042\u308b\u306e\u304b\u3092\u30ab\u30a6\u30f3\u30c8\u3059\u308bWord\u30de\u30af\u30ed\u3067\u3001\u7d50\u679c\u306f\u65b0\u3057\u3044\u6587\u66f8\u306b\u8868\u5f62\u5f0f\u3067\u51fa\u529b\u3057\u307e\u3059\u3002 \u30ab\u30a6\u30f3\u30c8\u3092\u884c\u3046\u300cCntWord\u300d\u95a2\u6570\u5185\u306e\u691c\u7d22\u6761\u4ef6\u3092\u5909\u66f4\u3059\u308c\u3070\u5f97\u3089\u308c [&hellip;]","protected":false},"author":1,"featured_media":7134,"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,49],"tags":[85,11,45],"class_list":["post-1558","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-word-office","tag-word-vba-2","tag-office-2","tag-word-"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Word.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-p8","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1558","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=1558"}],"version-history":[{"count":4,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1558\/revisions"}],"predecessor-version":[{"id":2231,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1558\/revisions\/2231"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7134"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}