{"id":1301,"date":"2017-05-08T16:01:36","date_gmt":"2017-05-08T07:01:36","guid":{"rendered":"http:\/\/okamurax.com\/?p=1301"},"modified":"2017-05-08T16:32:42","modified_gmt":"2017-05-08T07:32:42","slug":"c-%e5%b9%b4%e6%9c%88%e6%97%a5%e3%83%95%e3%82%a9%e3%83%ab%e3%83%80%e8%87%aa%e5%8b%95%e7%94%9f%e6%88%90%e4%bc%9a%e5%93%a1%e6%95%b0%e4%bf%9d%e5%ad%98-%e4%bd%9c%e3%82%8a%e3%81%8b%e3%81%91","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=1301","title":{"rendered":"C# VBA \u5e74\u6708\u65e5\u30d5\u30a9\u30eb\u30c0\u81ea\u52d5\u751f\u6210(\u4f1a\u54e1\u6570\u4fdd\u5b58) \u4f5c\u308a\u304b\u3051"},"content":{"rendered":"<p>\u5c11\u3057\u8a66\u4f5c\u3092\u4f5c\u308a\u59cb\u3081\u305f\u304c\u3001\u65b9\u5411\u6027\u304c\u5909\u308f\u3063\u305f\u305f\u3081\u3002<\/p>\n<p>Form1.cs<\/p>\n<pre class=\"lang:c# decode:true \" >\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.ComponentModel;\r\nusing System.Data;\r\nusing System.Drawing;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\nusing System.Windows.Forms;\r\n\r\nnamespace \u4f1a\u54e1\u6570\u4fdd\u5b58\r\n{\r\n    public partial class Form1 : Form\r\n    {\r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n\r\n            this.comboBox1.Items.Add(\"2017\");\r\n            this.comboBox1.Items.Add(\"2018\");\r\n\r\n            for (int i = 1; i &lt;= 12; i++ )\r\n            {\r\n                this.comboBox2.Items.Add(\r\n                    string.Format(\"{0:00}\",i)\r\n                    );\r\n            }\r\n\r\n            this.comboBox1.Text = DateTime.Today.ToString(\"yyyy\");\r\n            this.comboBox2.Text = DateTime.Today.ToString(\"MM\");\r\n\r\n            this.button1.Click += new EventHandler(MakeFolder);\r\n\r\n        }\r\n\r\n        private void MakeFolder(object sender, EventArgs e)\r\n        {\r\n            try\r\n            {\r\n                DateTime.Parse(comboBox1.Text + \"\/\" + comboBox2.Text + \"\/01\");\r\n\r\n                if(System.IO.File.Exists(Application.StartupPath + @\"\\dat.txt\"))\r\n                {\r\n                    MessageBox.Show(\"\u65e2\u306bdat.txt\u304c\u5b58\u5728\u3057\u307e\u3059\u3002\u4e2d\u6b62\u3057\u307e\u3059\u3002\");\r\n                    return;\r\n                }\r\n\r\n                string[] directories = System.IO.Directory.GetDirectories(Application.StartupPath);\r\n\r\n                if (directories.Length &gt; 0)\r\n                {\r\n                    MessageBox.Show(\"\u65e2\u306b\u540c\u4e00\u968e\u5c64\u306b\u30d5\u30a9\u30eb\u30c0\u304c\u5b58\u5728\u3057\u307e\u3059\u3002\u4e2d\u6b62\u3057\u307e\u3059\u3002\");\r\n                    return;\r\n                }\r\n\r\n                string targetPath = Application.StartupPath + \"\/\" + comboBox1.Text + comboBox2.Text;\r\n                System.IO.Directory.CreateDirectory(targetPath);\r\n\r\n                DateTime FromDate = DateTime.Parse(comboBox1.Text + \"\/\" + comboBox2.Text + \"\/01\");\r\n                DateTime ToDate = FromDate.AddMonths(1);\r\n                ToDate = ToDate.AddDays(-1);\r\n\r\n                while(FromDate &lt;= ToDate)\r\n                {\r\n                    System.IO.Directory.CreateDirectory(targetPath + \"\/\" + FromDate.ToString(\"dd\"));\r\n                    FromDate = FromDate.AddDays(1);\r\n                }\r\n\r\n                using(System.IO.StreamWriter sw = new System.IO.StreamWriter(\r\n                    Application.StartupPath + @\"\\dat.txt\",false,System.Text.Encoding.GetEncoding(\"Shift_Jis\")))\r\n                {\r\n                    sw.Write(comboBox1.Text + \"\\r\\n\" + comboBox2.Text + \"\\r\\n\" + ToDate.ToString(\"dd\"));\r\n                    sw.Close();\r\n                }\r\n\r\n            }\r\n            catch (Exception exp)\r\n            {\r\n                MessageBox.Show(exp.Message);\r\n                return;\r\n            }\r\n\r\n            MessageBox.Show(\"\u30d5\u30a9\u30eb\u30c0\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002\");\r\n\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>VBA<\/p>\n<pre class=\"lang:vb decode:true \" >\r\n\r\nSub auto_open()\r\n\r\nOn Error Resume Next\r\n\r\nApplication.CommandBars(\"cell\").Controls(\"\u4f1a\u54e1\u6570\u3092\u30d5\u30a9\u30eb\u30c0\u304b\u3089\u53d6\u5f97\").Delete\r\n\r\nWith Application.CommandBars(\"cell\").Controls.Add\r\n.OnAction = \"main\"\r\n.Caption = \"\u4f1a\u54e1\u6570\u3092\u30d5\u30a9\u30eb\u30c0\u304b\u3089\u53d6\u5f97\"\r\nEnd With\r\n\r\nEnd Sub\r\n\r\nSub auto_close()\r\n\r\nOn Error Resume Next\r\n\r\nApplication.CommandBars(\"cell\").Controls(\"\u4f1a\u54e1\u6570\u3092\u30d5\u30a9\u30eb\u30c0\u304b\u3089\u53d6\u5f97\").Delete\r\nApplication.CommandBars(\"cell\").Controls(\"\u4f1a\u54e1\u6570\u3092\u30d5\u30a9\u30eb\u30c0\u304b\u3089\u53d6\u5f97\").Delete\r\n\r\nEnd Sub\r\n\r\nSub main()\r\n\r\nOn Error GoTo e\r\n\r\ntargetPath = ThisWorkbook.Path &amp; \"\\dat.txt\"\r\n\r\nIf Dir(targetPath) = \"\" Then\r\n\r\n  MsgBox \"dat.txt\u304c\u5b58\u5728\u3057\u307e\u305b\u3093\u3002\u7d42\u4e86\u3057\u307e\u3059\u3002\"\r\n  Exit Sub\r\n\r\nEnd If\r\n\r\nOpen targetPath For Input As #1\r\n  Line Input #1, y\r\n  Line Input #1, m\r\n  Line Input #1, d\r\nClose #1\r\n\r\nFor i = 1 To d\r\n\r\n  targetPath = ThisWorkbook.Path &amp; \"\/\" &amp; y &amp; m &amp; \"\/\" &amp; Format(i, \"00\")\r\n  \r\n  If Dir(targetPath) = \"\" Then\r\n  \r\n    MsgBox targetPath &amp; \"\u304c\u5b58\u5728\u3057\u307e\u305b\u3093\u3002\u7d42\u4e86\u3057\u307e\u3059\u3002\"\r\n    Exit Sub\r\n  \r\n  End If\r\n  \r\n  ActiveSheet.Cells(i + 1, 1).Value = y &amp; \"\/\" &amp; m &amp; \"\/\" &amp; Format(i, \"00\")\r\n  'ActiveSheet.Cells(i + 1, 1).Font.Color = RGB(255, 0, 0)\r\n  'ActiveSheet.Cells(i + 1, 2).Value = ActiveSheet.Cells(i, 2).Value\r\n  'ActiveSheet.Cells(i + 1, 3).Value = ActiveSheet.Cells(i, 3).Value\r\n\r\nNext i\r\n\r\nExit Sub\r\n\r\ne:\r\n\r\nMsgBox \"\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u3044\u307e\u3059\u3002\"\r\n\r\nEnd Sub\r\n\r\nSub initialize()\r\n\r\nActiveSheet.Cells.Delete\r\nActiveSheet.Columns(\"A\").NumberFormatLocal = \"yyyy\/mm\/dd\"\r\nActiveSheet.Cells(1, 1).Value = \"\u65e5\u4ed8\"\r\nActiveSheet.Cells(1, 2).Value = \"\u65b0\u898f\"\r\nActiveSheet.Cells(1, 3).Value = \"\u66f4\u65b0\"\r\n\r\nEnd Sub\r\n\r\nSub finalize()\r\n\r\nActiveSheet.Columns.AutoFit\r\n\r\nEnd Sub\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5c11\u3057\u8a66\u4f5c\u3092\u4f5c\u308a\u59cb\u3081\u305f\u304c\u3001\u65b9\u5411\u6027\u304c\u5909\u308f\u3063\u305f\u305f\u3081\u3002 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel;  &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=1301\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;C# VBA \u5e74\u6708\u65e5\u30d5\u30a9\u30eb\u30c0\u81ea\u52d5\u751f\u6210(\u4f1a\u54e1\u6570\u4fdd\u5b58) \u4f5c\u308a\u304b\u3051&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9,5],"class_list":["post-1301","post","type-post","status-publish","format-standard","hentry","category-1","tag-c-net","tag-vba"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/1301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1301"}],"version-history":[{"count":2,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/1301\/revisions"}],"predecessor-version":[{"id":1303,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/1301\/revisions\/1303"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}