{"id":120,"date":"2017-07-01T09:05:13","date_gmt":"2017-07-01T00:05:13","guid":{"rendered":"https:\/\/jidouka.work\/?p=120"},"modified":"2018-08-15T13:19:04","modified_gmt":"2018-08-15T04:19:04","slug":"%e3%83%87%e3%82%a3%e3%83%ac%e3%82%af%e3%83%88%e3%83%aa%e5%86%85%e3%81%ae%e3%82%a8%e3%82%af%e3%82%bb%e3%83%ab%e3%81%ae%e3%82%b7%e3%83%bc%e3%83%88%e3%82%92%e5%85%a8%e3%81%a6%e7%b5%90%e5%90%88%e3%81%99","status":"publish","type":"post","link":"https:\/\/jidouka.work\/?p=120","title":{"rendered":"\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306e\u30a8\u30af\u30bb\u30eb\u306e\u30b7\u30fc\u30c8\u30921\u3064\u306e\u30d6\u30c3\u30af\u306b\u307e\u3068\u3081\u308b[VBA]"},"content":{"rendered":"<p>\u30d5\u30a9\u30eb\u30c0\u306e\u4e2d\u306b\u5b58\u5728\u3059\u308b\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u306e\u30b7\u30fc\u30c8\u30921\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u4e00\u77ac\u3067\u307e\u3068\u3081\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h2>VBA\u30de\u30af\u30ed\u306e\u6d41\u308c<\/h2>\n<p>\u4eca\u56de\u306e\u30de\u30af\u30ed\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u4ed5\u69d8\u3067\u3059\u3002<\/p>\n<ol>\n<li>\u5168\u3066\u306e\u30b7\u30fc\u30c8\u3092\u7d50\u5408\u3059\u308b\u305f\u3081\u306e\u65b0\u3057\u3044\u30d6\u30c3\u30af\u3092\u958b\u304f<\/li>\n<li>\u30e6\u30fc\u30b6\u306b\u30d6\u30c3\u30af\u306e\u3042\u308b\u30d5\u30a9\u30eb\u30c0\u3092\u9078\u629e\u3092\u4fc3\u3059<\/li>\n<li>\u30d5\u30a9\u30eb\u30c0\u5185\u306b\u3042\u308b\u5168\u3066\u306exlsx\u30d5\u30a1\u30a4\u30eb\u306e\u30b7\u30fc\u30c8\u3092\u65b0\u3057\u3044\u30b7\u30fc\u30c8\u3078\u30b3\u30d4\u30fc<\/li>\n<\/ol>\n<h2>\u30b3\u30fc\u30c9\u306e\u8aac\u660e<\/h2>\n<h3>\u65b0\u3057\u3044\u30ef\u30fc\u30af\u30d6\u30c3\u30af\u306e\u7528\u610f<\/h3>\n<p>\u65b0\u3057\u3044\u30ef\u30fc\u30af\u30d6\u30c3\u30af\u3092\u958b\u304f\u30b3\u30fc\u30c9\u306f<\/p>\n<p>Workbooks.Add<\/p>\n<p>\u3067\u3059\u3002<br \/>\n\u3053\u3053\u3067\u65b0\u3057\u3044\u30ef\u30fc\u30af\u30d6\u30c3\u30af\u306e\u540d\u524d\u3092\u53d6\u5f97\u3057\u3066\u304a\u304d\u307e\u3059\u3002\u3053\u306e\u30d6\u30c3\u30af\u306e\u540d\u524d\u306f\u5f8c\u3067\u30b7\u30fc\u30c8\u306e\u30b3\u30d4\u30fc\u5148\u3068\u3057\u3066\u6307\u5b9a\u3059\u308b\u305f\u3081\u3067\u3059\u3002<\/p>\n<p>newWbName = ActiveWorkbook.Name<\/p>\n<h3>\u30e6\u30fc\u30b6\u306b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u9078\u629e\u3055\u305b\u308b\u30c0\u30a4\u30a2\u30ed\u30b0\u3092\u8868\u793a\u3057\u3066\u30d1\u30b9\u3092\u53d6\u5f97\u3059\u308b<\/h3>\n<p>\u30d5\u30a9\u30eb\u30c0\u3092\u9078\u629e\u3059\u308b\u30c0\u30a4\u30a2\u30ed\u30b0\u3092\u8868\u793a\u3059\u308b\u65b9\u6cd5\u306f\u3044\u304f\u3064\u304b\u3042\u308a\u307e\u3059\u304c\u3001Application.FileDialog(msoFileDialogFolderPicker)\u304c\u4e00\u756a\u7c21\u5358\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u9078\u629e\u3055\u308c\u305f\u30d5\u30a9\u30eb\u30c0\u306e\u30d1\u30b9\u3092\u3000buf = .SelectedItems(1)\u3000\u3067\u53d6\u5f97\u3057\u3001xlsxFile = Dir(buf &amp; &#8220;\\*.xlsx&#8221;) \u3067\u53d6\u5f97\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b&#8221;\\*.xlsx&#8221;\u3092\u304f\u3063\u3064\u3051\u3066Dir\u95a2\u6570\u3092\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n*.xlsx\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u305d\u306e\u30d5\u30a9\u30eb\u30c0\u5185\u306b\u5b58\u5728\u3059\u308b.xlsx\u30d5\u30a1\u30a4\u30eb\u3092\u5168\u3066\u5217\u6319\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>xlsx\u30d5\u30a1\u30a4\u30eb\u306e\u6570\u3060\u3051\u30eb\u30fc\u30d7<\/h3>\n<p>Do While \u301c Loop \u3092\u4f7f\u7528\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u306e\u6570\u3060\u3051\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\nDo While xlsxFile &lt;&gt; &#8220;&#8221; \u3068\u3059\u308b\u3053\u3068\u3067Dir\u3067\u53d6\u5f97\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u540d\u30921\u3064\u305a\u3064\u53d6\u5f97\u3057\u3001\u30d5\u30a1\u30a4\u30eb\u540d\u304c\u306a\u304f\u306a\u3063\u305f\u6642\u70b9\u3067\u30eb\u30fc\u30d7\u3092\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n<h3>xlsx\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f<\/h3>\n<p>Workbooks.Open buf &amp; &#8220;\\&#8221; &amp; xlsxFile \u3067\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3053\u3053\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u306a\u306e\u306f\u3001Dir()\u95a2\u6570\u306f\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3057\u305f\u6642\u306b\u30d5\u30a1\u30a4\u30eb\u540d\u3057\u304b\u8fd4\u3055\u306a\u3044\u305f\u3081\u3001\u518d\u5ea6\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u30d1\u30b9\u306b\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u7e4b\u3052\u3066\u958b\u304f\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u3068\u3057\u3066\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>\u958b\u3044\u305f\u30d6\u30c3\u30af\u3092\u4e0d\u53ef\u8996\u306b\u3059\u308b<\/h3>\n<p>\u3053\u308c\u306f\u3042\u3063\u3066\u3082\u306a\u304f\u3066\u3082\u3069\u3061\u3089\u3067\u3082\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u3042\u3063\u305f\u65b9\u304c\u5b9f\u884c\u3057\u305f\u6642\u306b\u753b\u9762\u306b\u30a6\u30a3\u30f3\u30c9\u30a6\u304c\u51fa\u306a\u3044\u305f\u3081\u306b\u898b\u305f\u76ee\u7684\u306b\u7dba\u9e97\u3067\u3059\u3002<br \/>\nActiveWindow.Visible = False<\/p>\n<h3>\u958b\u3044\u305f\u30d6\u30c3\u30af\u306e\u30b7\u30fc\u30c8\u3092\u65b0\u3057\u3044\u30d6\u30c3\u30af\u306b\u30b3\u30d4\u30fc\u3059\u308b<\/h3>\n<p>\u958b\u3044\u305f\u30d6\u30c3\u30af\u306b\u3042\u308b\u30b7\u30fc\u30c8\u306e\u6570\u3060\u3051\u65b0\u3057\u3044\u30d6\u30c3\u30af\u306b\u30b7\u30fc\u30c8\u3092\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002<br \/>\n\u30b7\u30fc\u30c8\u306e\u6570\u3060\u3051\u30b3\u30d4\u30fc\u3092\u884c\u3046\u305f\u3081\u3001For Each \u301c Next\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>For Each tmpSheet In Workbooks(xlsxFile).Sheets \u306f\u958b\u3044\u305f\u30d6\u30c3\u30af\u306e\u30b7\u30fc\u30c8\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u9806\u6b21tmpSheet\u306b\u5165\u308c\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\ntmpSheet.Copy After:=Workbooks(newWbName).Sheets(1) \u3067\u30b7\u30fc\u30c8\u3092\u65b0\u3057\u3044\u30d6\u30c3\u30af\u306e1\u679a\u76ee\u306e\u30b7\u30fc\u30c8\u306e\u5f8c\u306b\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002<br \/>\nNext tmpSheet\u3067\u958b\u3044\u305f\u30d6\u30c3\u30af\u306e\u6b21\u306e\u30b7\u30fc\u30c8\u306e\u51e6\u7406\u306b\u79fb\u308a\u307e\u3059\u3002<\/p>\n<h3>xlsx\u30d5\u30a1\u30a4\u30eb\u3092\u9589\u3058\u308b<\/h3>\n<p>\u30b3\u30d4\u30fc\u304c\u7d42\u308f\u3063\u305f\u3089\u958b\u3044\u305f\u30d6\u30c3\u30af\u3092\u9589\u3058\u307e\u3059\u3002\u3053\u308c\u3092\u3057\u3066\u304a\u304b\u306a\u3044\u3068\u30d5\u30a1\u30a4\u30eb\u304c\u958b\u3044\u305f\u307e\u307e\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br \/>\nWorkbooks(xlsxFile).Close<\/p>\n<h2>\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n<p>\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u30d5\u30a9\u30eb\u30c0\u3092\u9078\u629e\u3059\u308b\u30c0\u30a4\u30a2\u30ed\u30b0\u304c\u51fa\u307e\u3059\u3002<br \/>\n\u30c6\u30b9\u30c8\u7528\u306b\u30a8\u30af\u30bb\u30eb\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5165\u308c\u305f\u30d5\u30a9\u30eb\u30c0\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/40307521244b636fef5911ae41c9b60f.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-122\" src=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/40307521244b636fef5911ae41c9b60f-300x228.jpg\" alt=\"\" width=\"300\" height=\"228\" srcset=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/40307521244b636fef5911ae41c9b60f-300x228.jpg 300w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/40307521244b636fef5911ae41c9b60f-768x584.jpg 768w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/40307521244b636fef5911ae41c9b60f-1024x779.jpg 1024w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/40307521244b636fef5911ae41c9b60f.jpg 1235w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u30b7\u30fc\u30c8\u304c\u65b0\u3057\u304f\u4f5c\u6210\u3055\u308c\u305f\u30d6\u30c3\u30af\u306b\u5168\u3066\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/94e57d22f89a12face6ea50e576a2d66.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-123\" src=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/94e57d22f89a12face6ea50e576a2d66-300x284.jpg\" alt=\"\" width=\"300\" height=\"284\" srcset=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/94e57d22f89a12face6ea50e576a2d66-300x284.jpg 300w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/94e57d22f89a12face6ea50e576a2d66-768x728.jpg 768w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/94e57d22f89a12face6ea50e576a2d66-1024x970.jpg 1024w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/94e57d22f89a12face6ea50e576a2d66.jpg 1160w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>\u4eca\u56de\u306e\u30b3\u30fc\u30c9<\/h2>\n<figure class=\"jd-code\"><button type=\"button\" class=\"jd-code-copy\">\u30b3\u30d4\u30fc<\/button><pre><code class=\"language-vbnet\">Option Explicit\r\n\r\nSub JointSheets()\r\n    Dim buf As String\r\n    Dim xlsxFile As String\r\n    Dim newWbName As String\r\n    Dim tmpSheet As Object\r\n    \r\n&#039;    \u65b0\u3057\u3044\u30ef\u30fc\u30af\u30d6\u30c3\u30af\u3092\u4f5c\u6210\u3001\u65b0\u3057\u3044WB\u304c\u30a2\u30af\u30c6\u30a3\u30d6\u306b\u306a\u308b\r\n    Workbooks.Add\r\n    newWbName = ActiveWorkbook.Name\r\n    \r\n    \r\n&#039;    \u6307\u5b9a\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306b\u3042\u308bxlsx\u30d5\u30a1\u30a4\u30eb\u3092\u3059\u3079\u3066\u5217\u6319\r\n    With Application.FileDialog(msoFileDialogFolderPicker)\r\n        If .Show = True Then\r\n            buf = .SelectedItems(1)\r\n            xlsxFile = Dir(buf &amp; &quot;\\*.xlsx&quot;)\r\n        End If\r\n    End With\r\n    \r\n&#039;    xlsx\u30d5\u30a1\u30a4\u30eb\u306e\u6570\u3060\u3051\u30eb\u30fc\u30d7\r\n    Do While xlsxFile &lt;&gt; &quot;&quot;\r\n    \r\n        &#039;    xlsx\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\r\n        Workbooks.Open buf &amp; &quot;\\&quot; &amp; xlsxFile\r\n        \r\n        &#039;    \u30d6\u30c3\u30af\u3092\u4e0d\u53ef\u8996\u306b\u3059\u308b\r\n        ActiveWindow.Visible = False\r\n        \r\n        &#039;    \u30d6\u30c3\u30af\u5185\u306e\u30b7\u30fc\u30c8\u306e\u6570\u3060\u3051\u30eb\u30fc\u30d7\r\n        For Each tmpSheet In Workbooks(xlsxFile).Sheets\r\n            &#039;    \u65b0\u3057\u3044\u30d6\u30c3\u30af\u306b\u958b\u3044\u305f\u30d6\u30c3\u30af\u306e\u30b7\u30fc\u30c8\u3092\u30b3\u30d4\u30fc\u3059\u308b\r\n            tmpSheet.Copy After:=Workbooks(newWbName).Sheets(1)\r\n        Next tmpSheet\r\n        \r\n        &#039;    xlsx\u30d5\u30a1\u30a4\u30eb\u3092\u9589\u3058\u308b\r\n        Workbooks(xlsxFile).Close\r\n        \r\n        &#039;    \u6b21\u306exlsx\u30d5\u30a1\u30a4\u30eb\u306b\u79fb\u308b\r\n        xlsxFile = Dir()\r\n    Loop\r\nEnd Sub<\/code><\/pre><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u30d5\u30a9\u30eb\u30c0\u306e\u4e2d\u306b\u5b58\u5728\u3059\u308b\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u306e\u30b7\u30fc\u30c8\u30921\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u4e00\u77ac\u3067\u307e\u3068\u3081\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":122,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-120","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-excel","category-vba"],"_links":{"self":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=120"}],"version-history":[{"count":6,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/120\/revisions"}],"predecessor-version":[{"id":351,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/120\/revisions\/351"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/media\/122"}],"wp:attachment":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}