{"id":1303,"date":"2012-02-22T16:16:59","date_gmt":"2012-02-22T07:16:59","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=1303"},"modified":"2012-09-05T16:48:25","modified_gmt":"2012-09-05T07:48:25","slug":"mdb%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%8b%e3%82%89%e8%aa%ad%e3%81%bf%e8%be%bc%e3%82%93%e3%81%a0%e5%8d%98%e8%aa%9e%e3%82%92%e6%a4%9c%e7%b4%a2%e3%81%97%e3%80%81%e3%83%92%e3%83%83%e3%83%88","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=1303","title":{"rendered":"MDB\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8aad\u307f\u8fbc\u3093\u3060\u5358\u8a9e\u3092\u691c\u7d22\u3057\u3001\u30d2\u30c3\u30c8\u3057\u305f\u3089\u5358\u8a9e\u306e\u610f\u5473\u3092\u30b3\u30e1\u30f3\u30c8\u306b\u3059\u308bWord\u30de\u30af\u30ed"},"content":{"rendered":"<p>\u300c<a href=\"\/\/www.ka-net.org\/blog\/?p=1294\" title=\"MDB(Access\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9)\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\u3059\u308bExcel\u30de\u30af\u30ed\" target=\"_blank\">MDB(Access\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9)\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\u3059\u308bExcel\u30de\u30af\u30ed<\/a>\u300d\u3067\u8f9e\u66f8\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\u3057\u305fMDB\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<br \/>\n\u6298\u89d2\u306a\u306e\u3067\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5229\u7528\u3057\u305fWord\u30de\u30af\u30ed\u3092\u8003\u3048\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nPublic Sub AddCommentFromMDB()\r\n  Dim DBFilePath As String\r\n  Dim con As String\r\n  Dim cn As Object\r\n  \r\n  Const TableName As String = &quot;tblDic&quot; '\u30c6\u30fc\u30d6\u30eb\u540d\r\n  Const FieldName1 As String = &quot;word&quot; '\u30d5\u30a3\u30fc\u30eb\u30c9\u540d1\r\n  Const FieldName2 As String = &quot;meaning&quot; '\u30d5\u30a3\u30fc\u30eb\u30c9\u540d2\r\n  \r\n  DBFilePath = ThisDocument.Path &amp; Application.PathSeparator &amp; &quot;MyDB.mdb&quot;\r\n  If Len(Dir(DBFilePath)) &lt; 1 Then\r\n    MsgBox &quot;MDB\u30d5\u30a1\u30a4\u30eb\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002&quot; &amp; vbCrLf &amp; &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, vbExclamation + vbSystemModal\r\n    Exit Sub\r\n  End If\r\n  con = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; &amp; DBFilePath\r\n  \r\n  Set cn = CreateObject(&quot;ADODB.Connection&quot;)\r\n  cn.Open con\r\n  With CreateObject(&quot;ADODB.Recordset&quot;)\r\n    '.Open TableName, cn, 1, 1\r\n    .Open &quot;SELECT * FROM &quot; &amp; TableName &amp; &quot; WHERE &quot; &amp; FieldName1 &amp; &quot; LIKE 'a%'&quot;, cn, 1, 1 '&quot;a&quot;\u304b\u3089\u59cb\u307e\u308b\u5358\u8a9e\u306e\u307f\u51e6\u7406\r\n    If .RecordCount &lt;&gt; 0 Then\r\n      .MoveFirst\r\n       Do Until .EOF\r\n         FindProc .Fields(FieldName1).Value, .Fields(FieldName2).Value\r\n         .MoveNext\r\n         DoEvents\r\n       Loop\r\n    End If\r\n    .Close\r\n  End With\r\n  cn.Close\r\n  Set cn = Nothing\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 FindProc(ByVal txt1 As String, ByVal txt2 As String)\r\n  Dim r As Word.Range\r\n  \r\n  Set r = ActiveDocument.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 = txt1\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      r.Comments.Add r, txt2 '\u30b3\u30e1\u30f3\u30c8\u8ffd\u52a0\r\n    Loop\r\n  End With\r\n  Set r = Nothing\r\nEnd Sub<\/pre>\n<p>\u4e0a\u8a18\u30de\u30af\u30ed\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001MDB\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8aad\u307f\u8fbc\u3093\u3060\u5358\u8a9e\u3092\u5143\u306bWord\u6587\u66f8\u5185\u3092\u691c\u7d22\u3057\u3001\u30d2\u30c3\u30c8\u3057\u305f\u5834\u5408\u306fMDB\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8aad\u307f\u8fbc\u3093\u3060\u5358\u8a9e\u306e\u610f\u5473\u3092\u30b3\u30e1\u30f3\u30c8\u306b\u3059\u308b\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n(\u5168\u30ec\u30b3\u30fc\u30c9\u3092\u51e6\u7406\u3059\u308b\u3068\u4ef6\u6570\u304c\u591a\u3044\u306e\u3067\u3001\u4e0a\u8a18\u30b3\u30fc\u30c9\u3067\u306fWHERE\u53e5\u3067\u51e6\u7406\u3059\u308b\u5358\u8a9e\u3092\u5236\u9650\u3057\u3066\u3044\u307e\u3059\u3002)<\/p>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/AddCommentFromMDB_01.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/AddCommentFromMDB_01-150x150.jpg\" alt=\"\" title=\"AddCommentFromMDB_01\" width=\"150\" height=\"150\" class=\"alignnone size-thumbnail wp-image-1304\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/AddCommentFromMDB_01-150x150.jpg 150w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/AddCommentFromMDB_01-75x75.jpg 75w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<p>\u4eca\u56de\u306f\u7c21\u5358\u306b\u30c6\u30b9\u30c8\u3057\u305f\u3060\u3051\u306a\u306e\u3067\u691c\u7d22\u7cbe\u5ea6\u3092\u8003\u616e\u3057\u3066\u3044\u307e\u305b\u3093\u3002<br \/>\n\u3088\u308a\u6b63\u78ba\u306b\u51e6\u7406\u3059\u308b\u5834\u5408\u306f\u3001\u691c\u7d22\u6761\u4ef6\u3084MDB\u306b\u683c\u7d0d\u3059\u308b\u30c7\u30fc\u30bf\u5185\u5bb9\u3092\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u300cMDB(Access\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9)\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\u3059\u308bExcel\u30de\u30af\u30ed\u300d\u3067\u8f9e\u66f8\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\u3057\u305fMDB\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002 \u6298\u89d2\u306a\u306e\u3067\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5229\u7528\u3057\u305fWord\u30de\u30af\u30ed\u3092\u8003\u3048\u3066\u307f\u307e\u3059\u3002 Option  [&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":[11,45,85],"class_list":["post-1303","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-word-office","tag-office-2","tag-word-","tag-word-vba-2"],"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-l1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1303","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=1303"}],"version-history":[{"count":5,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1303\/revisions"}],"predecessor-version":[{"id":2234,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1303\/revisions\/2234"}],"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=1303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}