1. ãã¯ããšVBAã®åºç€ç¥è
ãã¯ãã®åºæ¬çãªæŠå¿µãšçšé
ãã¯ãã¯ãäžé£ã®ã³ã³ãã¥ãŒã¿åœä»€ã1ã€ã®ã³ãã³ãã«ãŸãšããåäžã®åäœã§å®è¡ããããã®ããŒã«ã§ããå€ãã®å Žåãç¹°ãè¿ãçºçããåçŽãªäœæ¥ãèªååããããã«äœ¿çšãããŸããäŸãã°ãè¡šèšç®ãœããã§åæ§ã®åœ¢åŒãç¹°ãè¿ãäœæããå Žåããããã¹ãç·šéäœæ¥ã§åãã¹ã¿ã€ã«ã®é©çšãå¿ èŠãªå Žåã«ãã¯ããå©çšããããšã§ãæéãšåŽåãå€§å¹ ã«ç¯çŽã§ããŸãã
ãã¯ãã䜿çšããã«ã¯ãããŠã¹ã¯ãªãã¯ãããŒããŒãå ¥åãªã©ã®æäœãèšé²ããããããã¯ããšããŠä¿åããããšãäžè¬çã§ãããã®åŸãåæ§ã®ã¿ã¹ã¯ãè¡ãããæã«ã¯ãã®ãã¯ããå®è¡ããã ãã§ãèšé²ãããäžé£ã®æäœãèªåçã«åçŸãããã®ã§ããããã«ããããŠãŒã¶ãŒã¯å調ã§ç ©éãªäœæ¥ãã解æŸãããããåµé çãªã¿ã¹ã¯ã«éäžã§ããããã«ãªããŸãã
ãããã®å©ç¹ã«ããããã¯ãã¯ãªãã£ã¹ã¯ãŒã«ãŒãããŒã¿ã¢ããªã¹ãã«ãšã£ãŠéåžžã«æçšãªããŒã«ã§ããããã«ãå€ãã®ãªãã£ã¹ãœãããŠã§ã¢ããã¯ãã®èšé²ãå®è¡ãç°¡åã«ããæ©èœãæäŸããŠãããããããã°ã©ãã³ã°ã¹ãã«ããªã人ã§ãã¢ã¯ã»ã¹ããããã®ãç¹é·ã§ãã
VBAãšã¯äœãïŒVBAã®åºç€ãç解ãã
VBAãšã¯Visual Basic for Applicationsã®ç¥ã§ãMicrosoft Office補åã§äœ¿ãããããã°ã©ãã³ã°èšèªã§ããVBAã䜿çšããããšã§ããã¯ãã®æ©èœãããé²åãããè€éãªèªååã¹ã¯ãªãããã¢ããªã±ãŒã·ã§ã³ãäœæããããšãã§ããŸããVBAã§ã¯ãæ¡ä»¶åå²ãç¹°ãè¿ãåŠçãšãã£ãããã°ã©ãã³ã°åºæ¬æ§é ã®å©çšãå¯èœãšãªããŸãã
VBAã¯ããã¯ãã¬ã³ãŒããŒã§çæãããã³ãŒããåºã«ãããã«é«åºŠãªã«ã¹ã¿ãã€ãºãæ±ããããå Žåã«åœ¹ç«ã¡ãŸããå ·äœçã«ã¯ããŠãŒã¶ãŒãã©ãŒã ã®äœæããšã©ãŒåŠçã®å®è£ ãå€éšããŒã¿ããŒã¹ãžã®ã¢ã¯ã»ã¹ãªã©ãå«ãŸããŸããããã«ãããããæŽç·ŽããããŠãŒã¶ãŒäœéšãããµãŒãããŒãã£ã®ã·ã¹ãã ãšã®çµ±åãå®çŸå¯èœã«ãªããŸãã
VBAãå©çšããããã«ã¯ãåºæ¬çãªããã°ã©ãã³ã°ã¹ãã«ãå¿ é ã§ããããã®åãèªååã®èå²ãšå¯èœæ§ã倧ããåºãããŸããããã°ã©ãã³ã°ã®åå¿è ã§ããå°ããã€åŠã¶ããšã«ããã匷åãªããŒã«ãšããŠVBAã䜿ãããªãããšãã§ããããã«ãªããŸãã
ãã¯ããšVBAã®é¢é£æ§
ãã¯ããšVBAã¯å¯æ¥ã«é¢é£ããŠããŸãããã¯ãã¯VBAã®äžåœ¢æ ã§ãããéåžžãVBAã䜿çšããŠãã¯ããèšè¿°ãããŸããèšãæãããšããã¯ãã¯VBAã䜿ã£ãŠäœãããèªååã¹ã¯ãªããã®ãææç©ããªã®ã§ãããããããã¯ãã«èšé²ãããã®ã¯ç°¡åãªæäœã§ããã®ã«å¯ŸããŠãVBAã¯ããè€éã§æ¡ä»¶ä»ãã®åäœãã«ãŒããªã©ãå«ãããã°ã©ã ãäœãããšããéãããããŸãã
å®éã®æ¥åã§ã¯ãåå¿è ã¯ãŸããã¯ãã®èšé²ããå§ããŠããã®åŸã§çæãããã³ãŒãã確èªããVBAã®å ¥éãšããŸãããã®æ¹æ³ã«ããããŠãŒã¶ãŒã¯ãã¯ãã®æ§é ãç解ãããããããŒã¹ã«VBAã§ããé«åºŠãªã«ã¹ã¿ãã€ãºãæé©åãè¡ãããšãã§ããããã«ãªããŸãã
ãŸããäžéšã®ç¶æ³ã§ã¯VBAã³ãŒããçŽæ¥æžãå§ããããšã§ããã¯ãã¬ã³ãŒããŒãéããŠã¯éæã§ããªãç¹å®ã®æ©èœãåäœãå®è£ ããããšãå¯èœã§ãããã®ããããã¯ããå ¥éç¹ãšããŠæ©èœããVBAãããæ·±ãå¶åŸ¡ãå¯èœã«ããã¹ãããã¢ããããŒã«ãšãªãåŸãã®ã§ãã
ãªãã£ã¹èªååã«ããããã¯ããšVBAã®åœ¹å²
ãªãã£ã¹ã§ã®æ¥ã ã®äœæ¥ãå¹çåããããã«ã¯ããã¯ããšVBAã¯éåžžã«éèŠãªåœ¹å²ãæ ããŸãããããã®ããŒã«ã«ãã£ãŠãããŒã¿å ¥åã®èªååãå ±åæžã®äœæãã°ã©ãã®æŽæ°ãªã©æ§ã ãªå®åçãªäœæ¥ãç°¡åãã€è¿ éã«è¡ããããã«ãªããŸãã
å ·äœçã«ã¯ããã¯ãã䜿çšãäœæ¥ããã»ã¹ãèªååããããšã§ã人çºçãã¹ãåæžããäœæ¥ã®äžè²«æ§ãä¿ã¡ãªããçç£æ§ãé«ããããšãå¯èœã§ãããŸããVBAã䜿çšããããšã§ãã·ã¹ãã éã®ããŒã¿ã®è»¢éãå€æãè€éãªããŒã¿è§£æãªã©ãããå°éçãªèªååãå®çŸã§ããããã«ãªããŸãã
ãã¯ããšVBAãé©åã«æŽ»çšããããšã§ãåçŽãªã¿ã¹ã¯ã®èªååã ãã§ãªãããŠãŒã¶ãŒåºæã®ããŒãºã«åãããé«åºŠãªã¯ãŒã¯ãããŒãæ§ç¯ããããšãã§ãããããããžãã¹ããã»ã¹ã®å¹çåã«å€§ããå¯äžããããšãã§ããŸãããªãŒãã¡ãŒã·ã§ã³ããŒã«ãšããŠããããã¯åã ã®çç£æ§ã®åäžã ãã§ãªããããŒã ãçµç¹å šäœã®ããã©ãŒãã³ã¹ã®æ¹åã«ã倧ããªåœ±é¿ãäžããŠããŸãã
2. ãã¯ãã®äœææ¹æ³ãšæŽ»çš
ãã¯ããšã¯ãäžé£ã®ã³ãã³ããæ©èœãèªåçã«å®è¡ããããã®ã¹ã¯ãªãããããã°ã©ã ã®ããšã§ããç¹ã«ãªãã£ã¹ã¯ãŒã¯ã§ã¯ãå埩çãªäœæ¥ãå€§å¹ ã«ççž®ããããã«æŽ»çšãããŸãããã¯ãã®åºæ¬ãšãªãäœææ¹æ³ããèŠãŠãããŸãããã
ãšã¯ã»ã«ã§ã¯ããŠãŒã¶ãŒãè¡ãæäœãèšé²ããããããã¯ããšããŠä¿åããããšãã§ããŸãããã®èšé²ããããã¯ãã¯ãåãäœæ¥ãç¹°ãè¿ãéã«ããã¿ã³ã²ãšã€ã§å®è¡ããããšãå¯èœã§ããããã«ãããŠãŒã¶ãŒã®è² æ ãå€§å¹ ã«æžããŸãã
ãã¯ãã¯ãšã¯ã»ã«ã®ã¿ãªãããã¯ãŒãããã¯ãŒãã€ã³ããšãã£ãä»ã®ãªãã£ã¹ãœãããŠã§ã¢ã§ãå©çšããããšãã§ããŸããããã«ãã£ãŠããªãã£ã¹ã¹ã€ãŒãå šäœã®äœæ¥å¹çãåäžãããããšãå¯èœã«ãªããŸãã
ãšã¯ã»ã«ã§ã®ãã¯ãã®èšé²
ãšã¯ã»ã«ã§ãã¯ããèšé²ããã«ã¯ããŸããéçºãã¿ãã衚瀺ããå¿ èŠããããŸãããã®åŸãèšé²ããã¿ã³ãéžæããå®è¡ãããæäœãå®æœããŸãããããã®æäœããã¯ããšããŠèšé²ãããåŸã§åå©çšã§ããããã«ãªããŸãã
ãã¯ãã®èšé²äžã«ã¯ãã»ã«ã®éžæãããŒã¿ã®å ¥åãæ°åŒã®èšå®ãªã©ã®æ¥åžžçãªäœæ¥ãèªåçã«ã³ãŒããšããŠä¿åãããŠãããŸããæäœãçµäºãããããèšé²åæ¢ããã¿ã³ãã¯ãªãã¯ããŠãã¯ãã®èšé²ãå®äºãããŸãã
èšé²ããããã¯ãã¯ãéåžžã¯ãå人çšãã¯ãããã¯ãã«ä¿åããããããä»ã®ãšã¯ã»ã«ãã¡ã€ã«ã§åãäœæ¥ãå¿ èŠãªå Žåã«ãæ軜ã«å©çšã§ããŸãããã¯ãã®äžæ¬ç®¡çã容æã§ãã
ãã¯ãã®ç·šéãšã«ã¹ã¿ãã€ãº
èšé²ãããã¯ãã¯ãã®ãŸãŸã§ãéåžžã«äŸ¿å©ã§ãããããã«é«åºŠãªæ©èœãå ãããå Žåã«ã¯ç·šéãå¿ èŠã§ãããã¯ãã®ã³ãŒãã¯ããšã¯ã»ã«å ã®VBAãšãã£ã¿ãŒãçšããŠã«ã¹ã¿ãã€ãºããããšãã§ããŸãã
äŸãã°ãç¹å®ã®æ¡ä»¶äžã§ã®ã¿ãã¯ããå®è¡ãããããã«ãŒãã䜿ã£ãŠåãæäœãè€æ°åç¹°ãè¿ããããšãã£ãå Žåã«ã¯ãVBAãšãã£ã¿ãŒããããã°ã©ãã³ã°ã®ç¥èã䜿ã£ãŠãã¯ãã調æŽããŸãã
ç·šéã§ã¯ããã¯ããããåçãã€å¹ççã«ããããã®å€æ°å®£èšããšã©ãŒãã³ããªã³ã°ãªã©ã®ãã¯ããã¯ãéµã«ãªããŸããããããã®äœæ¥ãããŒã«åã£ãã«ã¹ã¿ãã€ãºãè¡ãããšã§ãäœæ¥å¹çã倧ããåäžãããããšãã§ããŸãã
ãã䜿çšããããã¯ãã®äŸ
ãã¯ãã¯ããŸããŸãªã·ãã¥ãšãŒã·ã§ã³ã§æŽ»çšãããŸãããç¹ã«ãã䜿çšããã代衚çãªãã®ã«ã¯ãããŒã¿ã®æŽåœ¢ãæžåŒèšå®ãå®åäœæ¥ã®èªååãªã©ããããŸãã
äŸãã°ãæ¯æåããã©ãŒãããã§å ±åæžãäœæããéãããããŒãããã¿ãŒã®èšå®ãã»ã«ã®è²åããæ°åŒã®æ¿å ¥ãšãã£ãäžé£ã®æäœããã¯ãã«èšé²ããŠããã°ã次åããã¯ãã¿ã³äžã€ã§ãããã®äœæ¥å šãŠãç¬æã«å®äºãããããšãã§ããŸãã
ä»ã«ãããã䜿çšããããã¯ããšããŠã¯ãããŒã¿ã®ã€ã³ããŒããšãšã¯ã¹ããŒããã¡ãŒã«éä¿¡ã®èªååãå®æçãªããŒã¿ããã¯ã¢ãããšãã£ããã®ãæããããŸãããããã®ãã¯ããé§äœ¿ããããšã§ãæéãæå¹ã«æŽ»çšããããšãå¯èœãšãªããŸãã
ãã¯ãã«ããæéç¯çŽãã¯ããã¯
ãã¯ããçšããæéç¯çŽãã¯ããã¯ã®æ倧ã®å©ç¹ã¯ãæäœæ¥ã§è¡ãæéã倧ããæžããã人çãšã©ãŒãæå°éã«æããããšãã§ããç¹ã§ããããçãæéã§å€§éã®ããŒã¿ãæ±ãããšãã§ããããã«ãªããŸãã
ãŸãããã¯ããå©çšããéã«ã¯ãã·ã§ãŒãã«ããããŒãèšå®ããŠããã«å¹æçã«äœæ¥ãé²ããããšãã§ããŸããé »ç¹ã«å®è¡ãããã¯ãã«ã·ã§ãŒãã«ããããŒãå²ãåœãŠãããšã§ãããŠã¹æäœãããããšãªããããŒããŒãã®ã¿ã§è¿ éã«äœæ¥ãè¡ãããšãã§ããŸãã
ããã«ãè€æ°ã®ãã¯ããçµã¿åãããããšã§ãããè€éãªèªååãå¯èœã«ãªããŸããããšãã°ãããŒã¿å ¥åãã¯ãã®åŸã«ããŒã¿åæãã¯ããå®è¡ãããã®çµæãã¬ããŒããšããŠåºåãããªã©ãäžé£ã®æµããäžåºŠã®æäœã§å®éã§ããããã«ããããšãå¯èœã§ãã
3. VBAã®ããã°ã©ãã³ã°å ¥é
ãšã¯ã»ã«ãªã©ã®ãã€ã¯ããœãããªãã£ã¹ãœãããŠã§ã¢ã®èªååãšæ¡åŒµã«æ¬ ãããªãã®ãVBAãããžã¥ã¢ã«ããŒã·ãã¯ã»ãã©ãŒã»ã¢ããªã±ãŒã·ã§ã³ã§ãããã®ã»ã¯ã·ã§ã³ã§ã¯ãVBAã䜿ã£ãŠããã°ã©ãã³ã°ã®äžçã«å ¥éããèªèº«ã®ãªãã£ã¹äœæ¥ãå¹ççã§è³¢ããã®ãžãšå€ããæ¹æ³ã«ã€ããŠåŠã³ãŸãã
VBAã¯ãéããã°ã©ããŒã§ãã¢ã¯ã»ã¹ããããããã°ã©ãã³ã°èšèªã§ããããã¯ãã®äœæãšã¯äžç·ãç»ããããé«åºŠãªã«ã¹ã¿ãã€ãºãšèªååãå®çŸããŸããããã«ãããç¹°ãè¿ãè¡ãããè€éãªã¿ã¹ã¯ãç°¡åã«åŠçãããããŠãŒã¶ãŒå®çŸ©é¢æ°ãäœæãããããããšãã§ããŸãã
ã§ã¯ããŸãã¯VBAãšãã£ã¿ã®ç«ã¡äžãæ¹ãããåºæ¬çãªæäœãããã°ã©ã ã®äœææ¹æ³ã«è³ããŸã§ããã®ã¹ããããè¿œã£ãŠãããŸãããã
VBAãšãã£ã¿ã®éå§ãšåºæ¬çãªæäœ
VBAãšãã£ã¿ãéå§ããã«ã¯ããªãã£ã¹ã¢ããªã±ãŒã·ã§ã³å ã§ãAltãããŒãšãF11ãããŒãåæã«æŒããŸããããã«ãããVBAãšãã£ã¿ã®ãŠã£ã³ããŠãéããã³ãŒããæžãå§ããããšãã§ããŸãã
ãšãã£ã¿å ã«ã¯è€æ°ã®ãŠã£ã³ããŠãããããããžã§ã¯ããšã¯ã¹ãããŒã©ã¯äœ¿çšäžã®ãªããžã§ã¯ããVBAãããžã§ã¯ãã管çãããããã£ãŠã£ã³ããŠãéããŠéžæãããªããžã§ã¯ãã®è©³çŽ°ãèšå®ã»è¡šç€ºããŸãããŸããã³ãŒããŠã£ã³ããŠã§ã¯å®éã«ããã°ã©ã ãèšè¿°ããå®è¡ããŸãã
åºæ¬çãªæäœãšããŠãæ°ããã¢ãžã¥ãŒã«ã®æ¿å ¥ããããã·ãŒãžã£ã®äœæãã³ãŒãã®å®è¡ãšãããã°ãªã©ãè¡ããŸããç·Žç¿ãéããããšã§ããããã®æäœãèªç¶ã«ã§ããããã«ãªããŸãã
VBAã®åºæ¬æ§æãšããã°ã©ãã³ã°ã®åå
VBAãåŠã¶äžã§æãåºç€ãšãªãã®ãããã®æ§æã§ããVBAã®åºæ¬æ§æã«ã¯å€æ°ã®å®£èšãæ¡ä»¶åå²ïŒIf…Then…ElseïŒãã«ãŒãïŒFor…NextãDo…LoopïŒãªã©ãå«ãŸããŸãã
å€æ°ã¯æ å ±ã®äžæä¿ç®¡å Žæã§ãããããã°ã©ã å®è¡äžã«ããŒã¿ãæ ŒçŽããã®ã«çšããããŸããæ¡ä»¶åå²ãã«ãŒãã¯ããã°ã©ã ã®æµããå¶åŸ¡ããããã«å¿ é ã§ãç¹°ãè¿ãå®è¡ããã¿ã¹ã¯ãå¹ççã«åŠçãããããšãã§ããŸãã
ãŸããVBAã«ã¯ãŠã£ã³ããŠãã¡ãã»ãŒãžããã¯ã¹ãæäœããããã®ãªããžã§ã¯ãæåæ©èœããããŸãããããã®åºæ¬ãç解ããæ£ãã䜿ãããªãããšãéèŠã§ãã
ç°¡åãªVBAããã°ã©ã ã®äœææ¹æ³
å®éã«ç°¡åãªVBAããã°ã©ã ãäœæããŠã¿ãŸããããäŸãã°ãExcelã§éžæãããŠããã»ã«ã«ç¹å®ã®æååãå ¥åãããã¯ãã¯ä»¥äžã®ããã«èšè¿°ã§ããŸãã
Sub EnterText()
ActiveCell.Value = “Hello World”
End Sub
ãã®ã³ãŒãã¯ããEnterTextããšããååã®ãµãããã·ãŒãžã£ïŒãã¯ãïŒãå®çŸ©ããŠãããå®è¡ãããšã¢ã¯ãã£ããªã»ã«ã«ãHello Worldããšããæååãå ¥åããŸããæãã·ã³ãã«ãªVBAããã°ã©ã ã®äžäŸãšããŠããã®ã³ãŒãã¯VBAã®åãå®æããããã®è¯ãåºçºç¹ãšãªããŸãã
VBAã§ã®ãšã©ãŒãã³ããªã³ã°
VBAããã°ã©ã ã§å¹æçãªãšã©ãŒãã³ããªã³ã°ãå®è£ ããããšã¯ãå®å®ããã¢ããªã±ãŒã·ã§ã³ãäœæããäžã§äžå¯æ¬ ã§ãããšã©ãŒãé©åã«åãæ±ãããšãªãæŸçœ®ãããšãäºæãã¬ãšã©ãŒãçºçããå Žåã«ããã°ã©ã ã匷å¶çµäºããå¯èœæ§ããããŸãã
åºæ¬çãªãšã©ãŒãã³ããªã³ã°ã¯ãOn Errorãã¹ããŒãã¡ã³ãã䜿çšããããšã§å®çŸã§ããããã«ãããšã©ãŒãçºçããæã«ç¹å®ã®ãšã©ãŒåŠçã«ãŒãã³ã«ãžã£ã³ããããããšãã§ããŸãã
ãšã©ãŒãã³ããªã³ã°ãå«ãVBAããã°ã©ã ã¯ããŠãŒã¶ãŒãã¬ã³ããªãŒã§ä¿¡é Œæ§ã®é«ããã®ãªããæœåšçãªåé¡ãæ©æã«æ€åºããŠå¯ŸåŠããããšãã§ããŸããæé©ãªãšã©ãŒãã³ããªã³ã°ã®å®è£ ã¯ãVBAããã°ã©ãã³ã°ã®ã¹ãã«ãããã«åäžãããéµãšãªãã§ãããã
4. ãã¯ããšVBAã®å ·äœçãªéã
æäœã®èªååã«ããããã¯ããšVBAã®æ§èœæ¯èŒ
ãã¯ãã¯ç¹ã«åå¿è ã«ãšã£ãŠåãçµã¿ããããããŠã¹ã¯ãªãã¯ãããŒããŒãå ¥åã®é²ç»ã«ãã£ãŠç°¡åã«æäœã®èªååãäœæã§ããããŒã«ã§ããäžæ¹ãVBAïŒVisual Basic for ApplicationsïŒã¯ããã°ã©ãã³ã°èšèªã䜿ã£ãŠããé«åºŠãªèªååãå¯èœã«ããŸããVBAã¯åŠçé床ãæ©ããããè€éãªã¿ã¹ã¯ãå®è¡ã§ãããããæ§èœé¢ã§ã¯VBAããã¯ããåé§ããŠããŸãã
ãã¯ãã«ããèªååã¯å®åäœæ¥ã«é©ããŠãããå°ãªãåŠç¿åŽåã§å©çšã§ããŸãããç¹°ãè¿ããã¿ãŒã³ã«äŸåãããããäŸå€çãªã±ãŒã¹ãè€æ°ã®ã¢ããªã±ãŒã·ã§ã³éããŸããäœæ¥ã«ã¯äžåãã§ããããã«å¯ŸããVBAã§ã¯Ifæãã«ãŒããšãã£ãããã°ã©ã æ§é ã䜿çšããŠãããæè»ãã€è€éãªã·ããªãªã«å¯Ÿå¿ããããšãã§ããŸãã
ãã®ãããç°¡åãªèªååãæ±ãããŠãŒã¶ãŒã«ã¯ãã¯ããæé©ã§ãããç¶æ³ã«å¿ããŠé«åºŠãªå¶åŸ¡ãå¿ èŠãªå ŽåããããŒã¿åæãããŒã¿ããŒã¹ç®¡çãšãã£ãå°éçãªäœæ¥ãèªååããå¿ èŠããããŠãŒã¶ãŒã«ã¯VBAã®å©çšãæšå¥šãããŸãã
ãã¯ããšVBAã«ãããè€é床ãšæè»æ§ã®éã
ãã¯ãã«ããäœæ¥èªååã¯äž»ã«ç°¡åãªã¿ã¹ã¯åãã§ãããŠãŒã¶ãŒã¯ç¹å®ã®äœæ¥ããã¯ãã¬ã³ãŒããŒã§é²ç»ãããããäœåºŠãå®è¡ããããšãå¯èœã§ããããã¯ãç¹ã«å®åçãªæ¥åãè¡ãããã®æéççž®ã«å¹æçã§ãããè€éãªã¹ãã«ãå¿ èŠãšããŸããã
äžæ¹ã§VBAã¯ãExcelãªã©ã®ã¢ããªã±ãŒã·ã§ã³ã«çµã¿èŸŒãŸããããã°ã©ãã³ã°ã€ã³ã¿ãŒãã§ãŒã¹ã䜿çšããåå¥ã®ããŒãºã«åãããŠçŽ°ããªã«ã¹ã¿ãã€ãºãå¯èœã§ããVBAã䜿çšããã«ã¯ãããã°ã©ãã³ã°ã«é¢ããåºç€ç¥èãå¿ èŠã«ãªãããããã¯ããšæ¯èŒããŠåŠç¿æ²ç·ã¯ããæ¥ã«ãªããŸããããã®åãæ¥åã®æè»æ§ãé«ãŸããŸãã
é·æçã«èŠãŠãè€éãªæ¥åããã»ã¹ãåãæ±ãå ŽåãããŠãŒã¶ãŒã®ç¹å®ã®èŠæã«åãããåŠçãæ±ããããå Žé¢ã§ã¯ãVBAã«ããããã°ã©ãã³ã°ãããé©ããŠãããšèšããã§ããããVBAã¯ããã¿ã³ã®ã¯ãªãã¯äžã€ã§è€æ°ã®ã¢ããªã±ãŒã·ã§ã³ãšå¯Ÿè©±ããããã«ãŒãã³å€ã®åäœãã·ãŒã ã¬ã¹ã«åŠçãããªã©ããã¯ãã§ã¯å¯Ÿå¿ããããªãæè»æ§ãæäŸããŸãã
ã»ãã¥ãªãã£ã®èŠ³ç¹ããã®ãã¯ããšVBA
ãã¯ããšVBAã¯äž¡è ãšãã»ãã¥ãªãã£ã®ãªã¹ã¯ãæ±ããŠããŸãããšãã«ãã¯ãã¯ããŠãŒã¶ãŒãæå³ããªããã¯ããå®è¡ããããšã«ãã£ãŠã»ãã¥ãªãã£è匱æ§ãçºçãããå¯èœæ§ããããŸãããã®ãããå€ãã®äŒæ¥ã§ã¯ãã¯ãã®å®è¡ãå¶éããŠããŸãã
VBAã¯ããè€éã§åŒ·åãªæ©èœãåããŠãããããæªæã®ããã³ãŒããçµã¿èŸŒãŸããéã®è¢«å®³ã倧ãããªããŸããèµ·åæã«ãã¯ãã®äœ¿çšèš±å¯ãæ±ããããããããžã¿ã«çœ²åããããã¯ãã®ã¿ã®å®è¡ãèš±å¯ãããŠããããšãå€ãã§ããããããå®ç§ãªä¿è·ãä¿éãããã®ã§ã¯ãããŸããã
é©åãªã»ãã¥ãªãã£å¯ŸçãšããŠã¯ããã¯ããVBAã¹ã¯ãªããã®å®è¡åã«å 容ãæ€èšŒããããšãä¿¡é Œã§ãããœãŒã¹ããã®ã¿ãã¯ããVBAãå ¥æããããšããããŠå®æçã«ã»ãã¥ãªãã£ã¢ããããŒããè¡ãããšãéèŠã§ããå©çšè ã¯åžžã«ã»ãã¥ãªãã£æèãæã€ããšã§ããªãã£ã¹äœæ¥ã®èªååãå®å šã«è¡ãããšãã§ããã§ãããã
ã¡ã³ããã³ã¹ãšæ¡åŒµæ§ã«ããããã¯ã察VBA
ãã¯ãã¯é²ç»ããæäœãåºã«åäœããããããã¯ããå®è¡ãããã¢ããªã±ãŒã·ã§ã³ã®ã€ã³ã¿ãŒãã§ãŒã¹ãå€æŽããããšããã®ãã¯ãã¯æŽæ°ããªããã°äœ¿çšã§ããªããªãå¯èœæ§ããããŸãããã®ãããã¡ã³ããã³ã¹ã®å¿ èŠæ§ãçããå ŽåããããŸãã
äžæ¹ãVBAã¯ã³ãŒãããŒã¹ã®ã¢ãããŒãããšããããã€ã³ã¿ãŒãã§ãŒã¹ã®å€æŽã«å¯ŸããŠãæè»ãªå¯Ÿå¿ãå¯èœã§ãããŸããäžåºŠäœæããVBAã¹ã¯ãªããã¯åå©çšãæ¡åŒµã容æã§ãä»ã®ãããžã§ã¯ããã¢ããªã±ãŒã·ã§ã³ã«å¿ããŠã«ã¹ã¿ãã€ãºãæ©èœè¿œå ãã§ãããšããå©ç¹ããããŸãã
ããã«ãVBAã¯ãããã°ããŒã«ãåããŠããããšã©ãŒã®ç¹å®ãã³ãŒãã®æé©åãè¡ããããã§ããããã«ãã£ãŠç¶ç¶çãªæ¹åããããããªããããå ç¢ãªèªååã·ã¹ãã ãæ§ç¯ããããšãå¯èœã«ãªããŸããçµæãšããŠãé·æçãªèŠéã§ãªãã£ã¹äœæ¥ãèªååããéã«ã¯ãVBAãé©ããéžæè¢ãšãªãããšãå€ãã§ãã
5. VBAã«ããé«åºŠãªãªãã£ã¹èªåå
Visual Basic for ApplicationsïŒVBAïŒã¯Microsoft Officeã¹ã€ãŒãã®èªååãšæ¡åŒµãå¯èœã«ããã匷åãªããã°ã©ãã³ã°èšèªã§ãããšã¯ã»ã«ãã¯ãŒããªã©ã®ã¢ããªã±ãŒã·ã§ã³ã«çµã¿èŸŒãŸããŠãããè€éãªäœæ¥ãèªååãããã¯ããäœæããããã®æè»æ§ãšæ©èœæ§ãæäŸããŠããŸãã
ãã¯ãã¯ç¹å®ã®ã¿ã¹ã¯ãèªååããã¹ã¯ãªããã®äžçš®ã§ãããVBAã¯ãããã®ãã¯ããèšè¿°ããã®ã«äœ¿ãããèšèªã§ãããã¯ããã«è€éãªããžãã¯ãæ©èœæ§ããµããŒãããŠããŸããäžæ¹ãã¯ãã¯äž»ã«ç¹°ãè¿ãã¿ã¹ã¯ãèšé²ããæ©èœã«éå®ãããŸãããVBAã¯ã¢ããªã±ãŒã·ã§ã³ã®æ©èœãæ¡åŒµããã«ã¹ã¿ãã€ãºå¯èœãªããŒã«ãã¢ããªã±ãŒã·ã§ã³ãäœæããããšãã§ããŸãã
VBAã¯ãå¹çæ§ãšçç£æ§ãé«ããããã«ãªãã£ã¹ã¢ããªã±ãŒã·ã§ã³ãããæå¹æŽ»çšããæ段ãæäŸãããããã£ãç¹ã§ãã¯ããããé²ãã éžæè¢ãæäŸããŸããããã§ã¯ãVBAãçšããŠå®çŸã§ãããªãã£ã¹èªååã®é«åºŠãªäŸã玹ä»ããŸãã
VBAã«ãããªãã£ã¹ã¢ããªã±ãŒã·ã§ã³éã®é£æº
VBAã¯Microsoft Officeã®å šã¢ããªã±ãŒã·ã§ã³ã§äœ¿çšå¯èœã§ãè€æ°ã®ã¢ããªã±ãŒã·ã§ã³ããŸããã£ãŠåäœããã¹ã¯ãªãããäœãããšãã§ããŸããäŸãã°ãExcelã§éèšãããããŒã¿ãèªåçã«PowerPointã®ã¹ã©ã€ãã«åæ ãããããWordã®ææžããããŒã¿ãæœåºããŠAccessããŒã¿ããŒã¹ã«æ ŒçŽãããªã©ãè€æ°ã®ã¢ããªã±ãŒã·ã§ã³ãé£æºãããããšãå¯èœã§ãã
ãããã®ããã»ã¹ã¯ããªãã£ã¹äœæ¥ã§ããèŠãããæåã®å ¥åãã¹ãæžå°ãããæ¥åã®å¹çåã«å€§ããè²¢ç®ããŸããVBAã«ããã¢ããªã±ãŒã·ã§ã³éã®é£æºã¯ãæ¥åãããŒãã¹ã ãŒãºã«ããé©åãªããŒã¿ã®æµãã確ä¿ã§ããããšãç¹é·ã§ãã
ããã«ãVBAã䜿çšããã°ããªãã£ã¹ã®ç°ãªãã¢ããªã±ãŒã·ã§ã³éã§è€éãªããžãã¹ããžãã¯ãå®è£ ããããšãã§ããããã«ãã£ãŠäžè²«æ§ã®ããã¬ããŒãã£ã³ã°ãåæãå®æœããããšãå¯èœã«ãªããŸãã
ãŠãŒã¶ãŒãã©ãŒã ãšã«ã¹ã¿ã ãã€ã¢ãã°ã®äœæ
VBAãå©çšããããšã§ãã«ã¹ã¿ã ãŠãŒã¶ãŒãã©ãŒã ããã€ã¢ãã°ããã¯ã¹ãäœæããããšãã§ããŸãããã®æ©èœã«ãããŠãŒã¶ãŒã¯ãã¢ããªã±ãŒã·ã§ã³ã®æšæºã€ã³ã¿ãŒãã§ãŒã¹ã«åãããããšãªããå¿ èŠã«å¿ããŠæè»ã«ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ããã¶ã€ã³ããããšãå¯èœã§ãã
äŸãã°ãç¹å®ã®ããŒã¿å ¥åã¿ã¹ã¯ã«å¿ èŠãªæ å ±ãåéããããã«ãã«ã¹ã¿ã ãã©ãŒã ãå©çšãããšããŠãŒã¶ãŒã¯ããçŽæçã«äœæ¥ãé²ããããšãã§ããåæã«ããŒã¿ã®äžè²«æ§ãšæ£ç¢ºæ§ãåäžããŸãã
ãŸãããããã®ãã©ãŒã ããã€ã¢ãã°ã¯ãã³ãŒããéããŠããã°ã©ã çã«å¶åŸ¡ããããšãã§ãããããããŒã¿ã®æ€èšŒãåŠçãèªååããããžãã¯ãçµã¿èŸŒãããšãå¯èœã§ããããã«ãããæ¥åããã»ã¹ãããå ç¢ãã€ä¿¡é Œæ§ã®ãããã®ã«ãªããŸãã
ããŒã¿ããŒã¹ãšãšã¯ã»ã«ã®VBAãçšããçµ±å
ããŒã¿ããŒã¹ç®¡çã·ã¹ãã ãšããŠã®Microsoft Accessãä»ã®SQLããŒã¹ã®ããŒã¿ããŒã¹ã¯ãExcelã¹ãã¬ããã·ãŒãã®VBAãšçµ±åããããšãã§ããŸãããã®çµ±åã掻çšãããšãExcelã®æè»æ§ãšããŒã¿ããŒã¹ã®åŒ·åãªããŒã¿ç®¡çèœåãå Œãåãããœãªã¥ãŒã·ã§ã³ãå®çŸããããšãã§ããŸãã
ç¹ã«ã倧èŠæš¡ãªããŒã¿ã¬ã³ãŒããæ±ãéãè€éãªããŒã¿ã¯ãšãªãå®è¡ããå Žåã«ãã®çµ±åã¯éåžžã«æå¹ã§ããVBAãä»ããããšã§ãExcelããçŽæ¥ããŒã¿ããŒã¹ã«ã¯ãšãªãéä¿¡ããããããŒã¿ãæœåºã»æŽæ°ããèªååãããã·ã¹ãã ãæ§ç¯ã§ããŸãã
ããã«ããã®æ¹æ³ã¯ããŒã¿åŠçã®é床ãåäžãããããé«åºŠãªããŒã¿åæãã¬ããŒãäœæãå¯èœã«ããŸããVBAãšããŒã¿ããŒã¹ã®çµ±åã¯ãããŒã¿äžå¿ã®ã¢ããªã±ãŒã·ã§ã³ã匷åããäžã§éèŠãªåœ¹å²ãæãããŸãã
ãšã¯ã»ã«å€éšããŒã¿æºãšã®VBAé£æºæè¡
VBAã¯ãå€éšããŒã¿ãœãŒã¹ãžã®ã¢ã¯ã»ã¹ãšæäœãèªååããèœåãæã£ãŠããŸããããã«ãããWebãµãŒãã¹ã®APIããããŒã¿ãååŸãããäŒæ¥å ã®ä»ã®ã·ã¹ãã ããããŒã¿ãã€ã³ããŒãããããããã¯FTPãµãŒããŒã«ãã¡ã€ã«ãã¢ããããŒããããšãã£ãäœæ¥ãå¯èœã«ãªããŸãã
ãã®å€éšé£æºæ©èœã¯ãæ¥åžžçã«çºçããå€æ§ãªããŒã¿äº€æããŒãºã«å¯Ÿå¿ããããåºãç¯å²ã§ã®èªååãå®çŸããŸããVBAã䜿ãããšã§ããªã¢ã«ã¿ã€ã ã®ããŒã¿ãã£ãŒããå®æçãªããŒã¿åæãšãã£ãåŠçãç°¡åã«èšå®ã»ç®¡çããããšãã§ããŸãã
ãã®ãããªæè¡ã¯ããšã¯ã»ã«ãåãªãã¹ãã¬ããã·ãŒãã¢ããªã±ãŒã·ã§ã³ãããããå æ¬çãªããžãã¹ããŒã¿åŠçããã³åæã®ãããžãšå€è²ãããŸããããžãã¹ã®çºå±ã«äŒŽã£ãŠå¢å€§ããããŒã¿åŠçã®ããŒãºã«å¯ŸããŠãVBAã¯åŒ·åãªè§£æ±ºçãæäŸããŸãã
6. ãã¯ããšVBAãèåãããå¿çšäºäŸ
æ¥åããã»ã¹æ¹åã«ããããã¯ããšVBAã®æŽ»çš
å€ãã®äŒæ¥ã«ãããŠããã¯ããšVBAã¯æ¥åããã»ã¹ã®æ¹åã«éèŠãªåœ¹å²ãæãããŠããŸãããªããŒãããäœæ¥ã®èªååã«ãã¯ãã䜿çšããäžæ¹ã§ãããé«åºŠãªããŒã¿åŠçãæ¡ä»¶åå²ãå¿ èŠãšããã¿ã¹ã¯ã«ã¯VBAãçšããããŸããäŸãã°ãæ¯æã®å ±åæžäœæã®éã«ãåºæ¬çãªããŒã¿å ¥åã¯ãã¯ãã«ãã£ãŠèªååããå ±åæžã®ãã©ãŒãããåãæ¿ããããŒã¿åæã¯VBAã«ãã£ãŠã«ã¹ã¿ã ã³ãŒãã§å®è¡ãããŸãã
æ¥åããã»ã¹ã®æ¹åäŸãšããŠã¯ã泚æ管çã·ã¹ãã ã§æ³šç®ãããã±ãŒã¹ããããŸãããã¯ãã¯æ³šææžã®ãã³ãã¬ãŒããèªåçã«çæããã®ã«å©çšãããVBAã¯ãããã®æ³šææ å ±ãããŒã¿ããŒã¹ãšåæãããåšåº«ç®¡çãçºæ³šåŠçãè¡ãéã®èªååã«åœ¹ç«ãŠãããŸãããã®ããã«ãã¯ããšVBAãçµã¿åãããããšã§ãäœæ¥æéãå€§å¹ ã«åæžãããšã©ãŒçºçã®å¯èœæ§ãæžããããšãã§ããŸãã
ãŸãããªã¢ã«ã¿ã€ã ã§ã®ããŒã¿åŠçãå¿ èŠãšãããããžã§ã¯ã管çã§ã¯ãåšæçãªã¹ããŒã¿ã¹ã¬ããŒãã®çæã«ãã¯ãããããŒã¿ã®åæãè€éãªèšç®ã«VBAã䜿ãããäž¡è ã®çµã¿åãããæ¥åã®å¹çåãå éããŸãããããã®äºäŸãããæãããªããã«ããã¯ããšVBAã®é©åãªèåã¯æ¥åããã»ã¹ãæ ¹æ¬ããæ¹åããåãæã£ãŠããŸãã
æ§ã ãªæ¥çã§ã®ãã¯ããšVBAã®äºäŸçŽ¹ä»
ãã¯ããšVBAã®èªååæè¡ã¯æ§ã ãªæ¥çã§å¿çšãããŠããŸããäŸãã°ãäŒèšæ¥çã§ã¯èšå€§ãªæ°ã®ãã©ã³ã¶ã¯ã·ã§ã³ãè¿ éã«åŠçããããã«ããã¯ããçšããŠåºæ¬çãªããŒã¿ãšã³ããªãŒäœæ¥ãèªååããVBAã«ãã£ãŠè€éãªè²¡ååæãäºç®ç®¡çã®ã¿ã¹ã¯ãè¡ãããŸããããã«ããäŒèšå£«ã¯ã«ãŒãã³ã¯ãŒã¯ãã解æŸããããã䟡å€ã®é«ãåææ¥åã«éäžã§ããããã«ãªããŸãã
æè²æ¥çã«ãããŠã¯ãè¬åž«ããã¯ãã䜿ã£ãŠææ¥è³æãäžæ¬ã§æŽæ°ããVBAãå©çšããŠã«ã¹ã¿ã è©äŸ¡ããŒã«ãéçºããããšããããŸãããã®ææ³ã«ãããè¬åž«ã¯äžè²«æ§ã®ããåŠç¿äœéšãæäŸãã€ã€ãçåŸã®æ瞟管çãããå¹ççã«è¡ãããšãã§ããŸãã
補é æ¥ã§ã¯ãçç£ã©ã€ã³ã®ç£èŠãšå質管çã«ãã¯ããšVBAãå©çšãããŸãããã¯ãã¯å®ååãããå ±åæžãäœæããVBAã¯ã»ã³ãµãŒããŒã¿ã®åæããã©ãã«ã·ã¥ãŒãã£ã³ã°ã«æ¬ ãããªãããã°ã©ã ã®äœæã«äœ¿ãããã®ã§ãããããã®äºäŸã¯ããã¯ããšVBAãæ¥çãåããå€æ§ãªåœ¢ã§æŽ»èºããŠããããšã瀺ããŠããŸãã
ãã¯ãããVBAãžç§»è¡ããéã®ãã¹ããã©ã¯ãã£ã¹
ãã¯ãã䜿ãå§ãããŠãŒã¶ãŒããæŽãªãèªååãšã«ã¹ã¿ãã€ãºãæ±ããŠVBAãžç§»è¡ããéã«ã¯ããã€ãã®ãã¹ããã©ã¯ãã£ã¹ã«åŸãããšãæšå¥šãããŸããæåã®ã¹ããããšããŠããã¯ããéããŠåºæ¬çãªèªååã®ä»çµã¿ãç解ãã次ã«VBAã®åºæ¬çãªææ³ããªããžã§ã¯ãã¢ãã«ãžã®ç解ãæ·±ããããšãéèŠã§ãã
ãŸããå°ãããããžã§ã¯ãããå§ããŠåŸã ã«è€éããå¢ããŠããã¢ãããŒããæçã§ããæšæºåããããšã©ãŒãã³ããªã³ã°ã®å®è£ ãã³ãŒãã®ããã¥ã¡ã³ãåãã¢ãžã¥ãŒã«åããããšã§ãèªã¿ãããã¡ã³ããã³ã¹ããããããã°ã©ã ãäœãããšãã§ããŸããããã«ãæ¢åã®ãã¯ããVBAã«å€æããŠåŸã ã«æ©èœãè¿œå ããŠããããšã§ãã¹ã ãŒãºãªç§»è¡ãå¯èœã«ãªããŸãã
æãéèŠãªã®ã¯ã移è¡ããéçšã§ã®ç¶ç¶çãªãã¹ããšãã£ãŒãããã¯ãåãå ¥ããäœå¶ãæŽããããšã§ããå®éã®æ¥åã§äœ¿çšããåã«ãæ§ã ãªã·ããªãªãæ³å®ããŠãã¹ããè¡ããåé¡ç¹ãä¿®æ£ããããšã§ããšã³ããŠãŒã¶ãŒã«ãšã£ãŠäœ¿ããããVBAã¢ããªã±ãŒã·ã§ã³ãäœæãããŸãã
ãã¯ããšVBAãçµã¿åãããè€åçèªååãœãªã¥ãŒã·ã§ã³
ãã¯ããšVBAã®çµã¿åããã«ããçã¿åºãããè€åçèªååãœãªã¥ãŒã·ã§ã³ã¯ãäŒæ¥ã«ãšã£ãŠèšãç¥ããªã䟡å€ãæã£ãŠããŸããããšãã°ããšã¯ã»ã«ã§ã¯ããã¯ãã§å®åçãªæžåŒèšå®ãäžæ¬ã§é©çšãããã®äžã§VBAã䜿ã£ãŠããŒã¿ã暪æçã«åæããããã·ã¥ããŒããçæããããšãã§ããŸããããã«ãã£ãŠããŒã¿ãçãçããšããããžã¥ã¢ã«ã«ãé åçãªã¬ããŒããäœæããããšãå¯èœã«ãªããŸãã
ãŸãããã¯ãã¯æ¥ã ã®å°ããªã¿ã¹ã¯ã®èªååã«éåžžã«å¹æçã§ãããVBAã¯ãããã®å°ããªèªååã®æçãäžã€ã®å€§ããªã¯ãŒã¯ãããŒã«é£æºãããããšãã§ããŸããäŸãã°ã顧客ããã®ã¡ãŒã«ã«åºã¥ããŠæ³šæãåŠçããã·ã¹ãã ã§ã¯ããã¯ããåä¿¡ãã¬ã€ãæŽçããVBAã泚ææ å ±ãæœåºããŠããŒã¿ããŒã¹ã«ä¿åããè«æ±æžãèªåçæããŸãããã®ããã«ãè€æ°ã®èªååèŠçŽ ãã·ãŒã ã¬ã¹ã«çµã¿åããããæ¥åã®å¹çæ§ãšæ£ç¢ºæ§ãåæã«åäžãããããšãã§ããŸãã
ãã®ãããªãœãªã¥ãŒã·ã§ã³ã®éçºã«ã¯ããã¯ããšVBAã®æ·±ãç解ãå¿ èŠã§ããããããããã¹ã¿ãŒããããšã§äŒæ¥ã¯å€§ããªç«¶äºåªäœãç²åŸããããšãã§ããŸããæçµçã«ãè·å Žã®çç£æ§ãé£èºçã«é«ããããšã«è²¢ç®ããåŸæ¥å¡ãããåµé çãªäœæ¥ã«å°å¿µã§ããç°å¢ãæŽããããšãæåŸ ãããã®ã§ãã
ãŸãšã
ãã¯ããšVBAã¯ããªãã£ã¹äœæ¥ãå¹çåããåªããããŒã«ã§ãã
ãã¯ã
ã¯ãšã¯ã»ã«çã§ç¹°ãè¿ãè¡ãäœæ¥ãèšé²ãåå©çšããæ©èœã§ãã
VBAïŒVisual Basic for ApplicationsïŒ
ã¯ãã¯ãã«æ¯ã¹ãŠããé«åºŠãªããã°ã©ãã³ã°ãå¯èœã§ãè€éãªäœæ¥ãèªååããŸãã
éã
ãšããŠããã¯ãã¯ã·ã³ãã«ãªæäœã«äŸ¿å©ã§ãããVBAã¯ã«ã¹ã¿ãã€ãºæ§ãé«ãããšã©ãŒãã³ããªã³ã°ãå€éšããŒã¿é£æºãè¡ããŸããããžãã¹ããŒãœã³ã®çããããããã䜿ãããªããŠæ¥ã ã®æ¥åãã¹ã ãŒãºã«é²ããŸãããã