{"id":2202,"date":"2018-01-25T00:38:48","date_gmt":"2018-01-24T15:38:48","guid":{"rendered":"http:\/\/okamurax.com\/?p=2202"},"modified":"2018-01-25T00:38:48","modified_gmt":"2018-01-24T15:38:48","slug":"vba-%e6%97%a5%e6%ac%a1%e3%83%81%e3%82%a7%e3%83%83%e3%82%af%e3%82%b7%e3%83%bc%e3%83%88%e7%94%9f%e6%88%90","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=2202","title":{"rendered":"VBA \u65e5\u6b21\u30c1\u30a7\u30c3\u30af\u30b7\u30fc\u30c8\u751f\u6210"},"content":{"rendered":"<pre class=\"lang:vb decode:true  \">Function holiday_chk(dt)\r\n\r\n'\u901a\u5e38\u306e\u4f11\u65e5\r\nIf Weekday(dt) = 1 Or Weekday(dt) = 7 Then\r\n  holiday_chk = True\r\n  Exit Function\r\nEnd If\r\n\r\n'\u795d\u65e5\r\nFor r = 3 To 30\r\n  If Sheets(\"\u8868\u7d19\").Cells(r, 4).Value = dt Then\r\n    holiday_chk = True\r\n    Exit Function\r\n  End If\r\nNext r\r\n\r\nholiday_chk = False\r\n\r\nEnd Function\r\nPrivate Sub CommandButton1_Click()\r\n\r\n'\u5165\u529b\u30c1\u30a7\u30c3\u30af --------------------------------------------------------\r\n\r\nIf IsDate(Sheets(\"\u8868\u7d19\").Cells(3, 2).Value) = False Then\r\n  MsgBox \"\u958b\u59cb\u65e5\u304c\u65e5\u4ed8\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\"\r\n  Exit Sub\r\nEnd If\r\n\r\nIf IsDate(Sheets(\"\u8868\u7d19\").Cells(6, 2).Value) = False Then\r\n  MsgBox \"\u7d42\u4e86\u65e5\u304c\u65e5\u4ed8\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\"\r\n  Exit Sub\r\nEnd If\r\n\r\nIf Sheets(\"\u8868\u7d19\").Cells(3, 2).Value &gt;= Sheets(\"\u8868\u7d19\").Cells(6, 2).Value Then\r\n  MsgBox \"\u958b\u59cb\u65e5\u3068\u7d42\u4e86\u65e5\u306e\u95a2\u4fc2\u304c\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002\"\r\n  Exit Sub\r\nEnd If\r\n\r\n'\u30b4\u30df\u5206\u5225 --------------------------------------------------------\r\n\r\nSheets(\"\u30b4\u30df\u5206\u5225\u539f\u672c(\u96db\u5f62)\").Copy after:=Sheets(\"\u8868\u7d19\")\r\nSet g = ActiveSheet\r\n\r\nr = 7\r\ndt = Sheets(\"\u8868\u7d19\").Cells(3, 2).Value\r\nDo While dt &lt;= Sheets(\"\u8868\u7d19\").Cells(6, 2).Value\r\n\r\n  f = holiday_chk(dt)\r\n  \r\n  '\u8868\u793a\u5f62\u5f0f\r\n  If r = 7 Then\r\n    g.Cells(r, 1).NumberFormatLocal = \"yyyy\/mm\/dd\"\r\n  Else\r\n    g.Cells(r, 1).NumberFormatLocal = \"mm\/dd\"\r\n  End If\r\n  \r\n  g.Cells(r, 3).NumberFormatLocal = \"aaa\"\r\n  \r\n  '\u914d\u7f6e\r\n  g.Cells(r, 5).HorizontalAlignment = xlCenter\r\n  g.Cells(r, 6).HorizontalAlignment = xlCenter\r\n  g.Cells(r, 7).HorizontalAlignment = xlCenter\r\n  g.Cells(r, 9).HorizontalAlignment = xlCenter\r\n  \r\n  '\u4f11\u65e5\u306e\u5834\u5408\r\n  If f = True Then g.Range(g.Cells(r, 1), g.Cells(r, 9)).Interior.Color = RGB(222, 222, 222)\r\n  \r\n  '\u7f6b\u7dda\r\n  g.Range(g.Cells(r, 1), g.Cells(r, 9)).Borders.LineStyle = True\r\n  \r\n  '\u5024\r\n  g.Cells(r, 1).Value = dt '\u65e5\u4ed8\r\n  g.Cells(r, 3).Value = dt '\u66dc\u65e5\r\n  \r\n  '\u4f11\u65e5\u3067\u306f\u7121\u3044\u5834\u5408\r\n  If f = False Then\r\n    g.Cells(r, 5).Value = \"\u25cb\" '\u4e00\u822c\u5ec3\u68c4\u7269\u30b4\u30df\r\n    g.Cells(r, 6).Value = \"\u25cb\" '\u5ec3\u30d7\u30e9\u30b9\u30c1\u30c3\u30af\u985e\r\n    g.Cells(r, 7).Value = \"\u25cb\" '\u91d1\u5c5e\u304f\u305a\r\n    g.Cells(r, 8).Value = \"\" '\u5099\u8003\r\n    tmp = Int((15 - 9 + 1) * Rnd + 9)\r\n    g.Cells(r, 9).Value = Sheets(\"\u8868\u7d19\").Cells(tmp, 2).Value '\u30c1\u30a7\u30c3\u30af\u8005\r\n  End If\r\n  \r\nr = r + 1\r\ndt = DateAdd(\"d\", 1, dt)\r\nLoop\r\n\r\n'\u8868\u984c\r\ng.Cells(2, 1).Value = \"\u3000\u3000\u25bc\" &amp; Sheets(\"\u8868\u7d19\").Cells(18, 2).Value &amp; \"\u5e74\u5ec3\u68c4\u7269\u5206\u5225\u30c1\u30a7\u30c3\u30af\u8868\"\r\n\r\n'\u4f5c\u6210\u65e5\r\nFor Each sh In g.Shapes\r\n  If sh.Type = msoTextBox Then\r\n    If sh.TextFrame.Characters.Text = \"x\" Then\r\n      sh.TextFrame.Characters.Text = \"\u4f5c\u6210\u65e5 \" &amp; Sheets(\"\u8868\u7d19\").Cells(21, 2).Value\r\n    End If\r\n  End If\r\nNext\r\n\r\n'\u7167\u660e\u30c1\u30a7\u30c3\u30af --------------------------------------------------------\r\n\r\nSheets(\"\u7167\u660e\u30c1\u30a7\u30c3\u30af(\u96db\u5f62)\").Copy after:=Sheets(\"\u8868\u7d19\")\r\nSet s = ActiveSheet\r\n\r\nr = 9\r\ndt = Sheets(\"\u8868\u7d19\").Cells(3, 2).Value\r\nDo While dt &lt;= Sheets(\"\u8868\u7d19\").Cells(6, 2).Value\r\n\r\n  f = holiday_chk(dt)\r\n  \r\n  '\u8868\u793a\u5f62\u5f0f\r\n  If r = 9 Then\r\n    s.Cells(r, 1).NumberFormatLocal = \"yyyy\/mm\/dd\"\r\n  Else\r\n    s.Cells(r, 1).NumberFormatLocal = \"mm\/dd\"\r\n  End If\r\n  \r\n  s.Cells(r, 3).NumberFormatLocal = \"aaa\"\r\n  \r\n  '\u914d\u7f6e\r\n  s.Cells(r, 5).HorizontalAlignment = xlCenter\r\n  s.Cells(r, 6).HorizontalAlignment = xlCenter\r\n  s.Cells(r, 7).HorizontalAlignment = xlCenter\r\n  s.Cells(r, 8).HorizontalAlignment = xlCenter\r\n  s.Cells(r, 9).HorizontalAlignment = xlCenter\r\n  s.Cells(r, 11).HorizontalAlignment = xlCenter\r\n  \r\n  '\u4f11\u65e5\u306e\u5834\u5408\r\n  If f = True Then s.Range(s.Cells(r, 1), s.Cells(r, 11)).Interior.Color = RGB(222, 222, 222)\r\n  \r\n  '\u7f6b\u7dda\r\n  s.Range(s.Cells(r, 1), s.Cells(r, 11)).Borders.LineStyle = True\r\n  \r\n  '\u5024\r\n  s.Cells(r, 1).Value = dt '\u65e5\u4ed8\r\n  s.Cells(r, 3).Value = dt '\u66dc\u65e5\r\n  \r\n  '\u4f11\u65e5\u3067\u306f\u7121\u3044\u5834\u5408\r\n  If f = False Then\r\n    s.Cells(r, 5).Value = \"\u25cb\" '\u7167\u660e\r\n    s.Cells(r, 6).Value = \"\u25cb\" '\u7a7a\u8abf\r\n    s.Cells(r, 7).Value = \"\u25cb\" '\u30de\u30b7\u30f3\r\n    s.Cells(r, 8).Value = \"\u25cb\" '\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\r\n    s.Cells(r, 9).Value = \"\u25cb\" '\u30d7\u30ea\u30f3\u30bf\r\n    tmp = Int((15 - 9 + 1) * Rnd + 9)\r\n    s.Cells(r, 11).Value = Sheets(\"\u8868\u7d19\").Cells(tmp, 2).Value '\u30c1\u30a7\u30c3\u30af\u8005\r\n  End If\r\n  \r\nr = r + 1\r\ndt = DateAdd(\"d\", 1, dt)\r\nLoop\r\n\r\n'\u8868\u984c\r\ns.Cells(2, 1).Value = \"\u3000\u3000\u25bc\" &amp; Sheets(\"\u8868\u7d19\").Cells(18, 2).Value &amp; \"\u5e74\u7701\u30a8\u30cd\u30c1\u30a7\u30c3\u30af\u8868\"\r\n\r\n'\u4f5c\u6210\u65e5\r\nFor Each sh In s.Shapes\r\n  If sh.Type = msoTextBox Then\r\n    If sh.TextFrame.Characters.Text = \"x\" Then\r\n      sh.TextFrame.Characters.Text = \"\u4f5c\u6210\u65e5 \" &amp; Sheets(\"\u8868\u7d19\").Cells(21, 2).Value\r\n    End If\r\n  End If\r\nNext\r\n\r\nEnd Sub\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Function holiday_chk(dt) &#8216;\u901a\u5e38\u306e\u4f11\u65e5 If Weekday(dt) = 1 Or Weekday(dt) = 7 Then holiday_chk = True Exit Function En &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=2202\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;VBA \u65e5\u6b21\u30c1\u30a7\u30c3\u30af\u30b7\u30fc\u30c8\u751f\u6210&#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":[5],"class_list":["post-2202","post","type-post","status-publish","format-standard","hentry","category-1","tag-vba"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2202","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=2202"}],"version-history":[{"count":1,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2202\/revisions"}],"predecessor-version":[{"id":2203,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2202\/revisions\/2203"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}