{"id":129,"date":"2017-07-02T12:42:33","date_gmt":"2017-07-02T03:42:33","guid":{"rendered":"https:\/\/jidouka.work\/?p=129"},"modified":"2017-07-04T13:56:00","modified_gmt":"2017-07-04T04:56:00","slug":"%e3%82%8f%e3%81%8b%e3%82%89%e3%81%aa%e3%81%84vba%e3%82%b3%e3%83%bc%e3%83%89%e3%82%92%e8%aa%bf%e3%81%b9%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/jidouka.work\/?p=129","title":{"rendered":"\u308f\u304b\u3089\u306a\u3044VBA\u30b3\u30fc\u30c9\u3092\u8abf\u3079\u308b\u65b9\u6cd5[VBA]"},"content":{"rendered":"<h2>\u4e0d\u660e\u306aVBA\u30b3\u30fc\u30c9\u3092\u8abf\u3079\u308b\u65b9\u6cd5<\/h2>\n<p>Excel\u3067VBA\u30de\u30af\u30ed\u3092\u4f5c\u6210\u3057\u3066\u3044\u3066\u300c\u3053\u306e\u52d5\u4f5c\u3092\u3055\u305b\u308b\u30b3\u30fc\u30c9\u3001\u3069\u3046\u66f8\u3044\u305f\u3089\u3044\u3044\u3093\u3060\u308d\u3046\u300d\u3068\u308f\u304b\u3089\u306a\u304f\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u305d\u3046\u3044\u3063\u305f\u4e0d\u660e\u306a\u30b3\u30fc\u30c9\u3092\u6642\u306b\u8abf\u3079\u308b\u65b9\u6cd5\u3068\u3057\u3066\u4ee5\u4e0b\u306e\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u30b0\u30fc\u30b0\u30eb\u3067\u8abf\u3079\u308b<\/li>\n<li>\u30a8\u30af\u30bb\u30eb\u306e\u672c\u3067\u8abf\u3079\u308b<\/li>\n<li>\u30de\u30af\u30ed\u3092\u8a18\u9332\u3057\u3066\u5b9f\u73fe\u3057\u305f\u3044\u4f5c\u696d\u3092\u884c\u3063\u3066\u307f\u308b<\/li>\n<\/ol>\n<p>\u4e0a2\u3064\u306f\u5f53\u305f\u308a\u524d\u3067\u3059\u304c\u3001\u3042\u308b\u7a0b\u5ea6VBA\u306e\u3053\u3068\u3092\u5b66\u7fd2\u3057\u305f\u4eba\u304c\u30b3\u30fc\u30c9\u3092\u78ba\u8a8d\u3059\u308b\u65b9\u6cd5\u3068\u3057\u3066\u306f3\u756a\u76ee\u3082\u975e\u5e38\u306b\u6709\u52b9\u3067\u3059\u3002<br \/>\n\u52d5\u4f5c\u306e\u30b3\u30fc\u30c9\u304c\u305d\u306e\u307e\u307e\u5165\u3063\u3066\u304f\u308c\u308b\u305f\u3081\u3001\u3069\u3046\u3044\u3046\u3075\u3046\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u3051\u3070\u3044\u3044\u306e\u304b\u3068\u3044\u3063\u305f\u3053\u3068\u304c\u308f\u304b\u308a\u3084\u3059\u3044\u3067\u3059\u3002<\/p>\n<h2>CSV\u306b\u51fa\u529b\u3059\u308b\u65b9\u6cd5\u3092\u8abf\u3079\u308b<\/h2>\n<p>\u4f8b\u3068\u3057\u3066\u4eca\u56de\u306fCSV\u5f62\u5f0f\u3067\u4fdd\u5b58\u3059\u308b\u65b9\u6cd5\u3092\u8abf\u3079\u307e\u3059\u3002<br \/>\nExcel\u3067\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u3068\u304d\u306f\u57fa\u672c\u7684\u306bxlsx\u5f62\u5f0f\u3067\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u3088\u3063\u3066\u306fCSV\u5f62\u5f0f\u3067\u306e\u30a4\u30f3\u30dd\u30fc\u30c8\u306e\u307f\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u591a\u3005\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u30b3\u30fc\u30c9\u3092\u8abf\u3079\u308b\u305f\u3081\u306b\u307e\u305a\u3001\u30de\u30af\u30ed\u306e\u8a18\u9332\u3092\u958b\u59cb\u3057\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/2f57272198e23a4f547ca405e580e2c2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-130\" src=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/2f57272198e23a4f547ca405e580e2c2-300x251.jpg\" alt=\"\" width=\"300\" height=\"251\" srcset=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/2f57272198e23a4f547ca405e580e2c2-300x251.jpg 300w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/2f57272198e23a4f547ca405e580e2c2.jpg 620w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u8a18\u9332\u3057\u305f\u3044\u52d5\u4f5c\uff08\u30d5\u30a1\u30a4\u30eb\u3092CSV UTF-8\uff09\u3067\u4fdd\u5b58\u3092\u3057\u3001\u30de\u30af\u30ed\u306e\u8a18\u9332\u3092\u505c\u6b62\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/d5672004ddd7103cd4dac0fa973b6002-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-132\" src=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/d5672004ddd7103cd4dac0fa973b6002-1-300x198.jpg\" alt=\"\" width=\"300\" height=\"198\" srcset=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/d5672004ddd7103cd4dac0fa973b6002-1-300x198.jpg 300w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/d5672004ddd7103cd4dac0fa973b6002-1-768x506.jpg 768w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/d5672004ddd7103cd4dac0fa973b6002-1.jpg 932w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u8a18\u9332\u3055\u308c\u305f\u30b3\u30fc\u30c9\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/abd0616ab9c83ea69299492d5b5c7b1f.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-133\" src=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/abd0616ab9c83ea69299492d5b5c7b1f-300x149.jpg\" alt=\"\" width=\"300\" height=\"149\" srcset=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/abd0616ab9c83ea69299492d5b5c7b1f-300x149.jpg 300w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/abd0616ab9c83ea69299492d5b5c7b1f-768x382.jpg 768w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/abd0616ab9c83ea69299492d5b5c7b1f-1024x509.jpg 1024w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/abd0616ab9c83ea69299492d5b5c7b1f.jpg 1319w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u3060\u3068\u30d5\u30a1\u30a4\u30eb\u540d\u3084\u4fdd\u5b58\u5148\u304c\u56fa\u5b9a\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u6c4e\u7528\u6027\u304c\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<h2>\u8a18\u9332\u3057\u305f\u30b3\u30fc\u30c9\u3092\u5229\u7528\u3057\u3066\u30de\u30af\u30ed\u3092\u5b8c\u6210\u3055\u305b\u308b<\/h2>\n<p><a href=\"https:\/\/jidouka.work\/?p=120\">\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<\/a>\u306e\u5fdc\u7528\u3068\u306a\u308a\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u6307\u5b9a\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306exlsx\u30d5\u30a1\u30a4\u30eb\u306b\u542b\u307e\u308c\u308b\u30b7\u30fc\u30c8\u3092\u5168\u3066csv\u5f62\u5f0f\u3067\u51fa\u529b\u3059\u308b\u30de\u30af\u30ed\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\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\nDim buf As String\r\nDim xlsxFile As String\r\nDim newFileName As String\r\n\r\n    \r\nSub Macro1()\r\n&#039;\r\n&#039; Macro1 Macro\r\n&#039;\r\n\r\n&#039;\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;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 &amp;lt;&amp;gt; &quot;&quot;\r\n    \r\n        &#039;    xlsx\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\r\n        Workbooks.Open buf &amp;amp; &quot;\\&quot; &amp;amp; xlsxFile\r\n        \r\n        &#039;    \u30d5\u30a1\u30a4\u30eb\u540d\u306e.xlsx\u3092.csv\u306b\u3059\u308b\r\n        newFileName = Replace(xlsxFile, &quot;.xlsx&quot;, &quot;.csv&quot;)\r\n        \r\n        &#039;    CSV\u5f62\u5f0f\u306eUTF-8\u3067\u4fdd\u5b58\r\n        Workbooks(xlsxFile).SaveAs Filename:= _\r\n        buf &amp;amp; &quot;\\&quot; &amp;amp; newFileName, FileFormat:=xlCSVUTF8, _\r\n        CreateBackup:=False\r\n       \r\n        \r\n        &#039;    xlsx\u30d5\u30a1\u30a4\u30eb\u3092\u9589\u3058\u308b\r\n        Workbooks(newFileName).Close\r\n        \r\n        &#039;    \u6b21\u306exlsx\u30d5\u30a1\u30a4\u30eb\u306b\u79fb\u308b\r\n        xlsxFile = Dir()\r\n    Loop\r\n\r\n\r\n    \r\nEnd Sub<\/code><\/pre><\/figure>\n<h2>\u5b9f\u884c\u7d50\u679c<\/h2>\n<p>\u5b9f\u884c\u3059\u308b\u3068\u6307\u5b9a\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u306bCSV\u30d5\u30a1\u30a4\u30eb\u304c\u51fa\u529b\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/1800d7053b8f7f3d3e4120ac94f9c707.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/1800d7053b8f7f3d3e4120ac94f9c707-300x145.jpg\" alt=\"\" width=\"300\" height=\"145\" class=\"alignnone size-medium wp-image-137\" srcset=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/1800d7053b8f7f3d3e4120ac94f9c707-300x145.jpg 300w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/1800d7053b8f7f3d3e4120ac94f9c707-768x370.jpg 768w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/1800d7053b8f7f3d3e4120ac94f9c707.jpg 989w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0d\u660e\u306aVBA\u30b3\u30fc\u30c9\u3092\u8abf\u3079\u308b\u65b9\u6cd5 Excel\u3067VBA\u30de\u30af\u30ed\u3092\u4f5c\u6210\u3057\u3066\u3044\u3066\u300c\u3053\u306e\u52d5\u4f5c\u3092\u3055\u305b\u308b\u30b3\u30fc\u30c9\u3001\u3069\u3046 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":130,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[9],"class_list":["post-129","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-excel","category-vba","tag-csv"],"_links":{"self":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/129","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=129"}],"version-history":[{"count":4,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/129\/revisions"}],"predecessor-version":[{"id":147,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/129\/revisions\/147"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/media\/130"}],"wp:attachment":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}