Dir´Ø¿ô¤ò·«¤êÊÖ¤·»È¤¦¾ì¹ç¤ÎÃí°Õ(¥¨¥¯¥»¥ë2010VBA)
Dir´Ø¿ô¤ò·«¤êÊÖ¤·¤Æ»È¤¦¾ì¹ç¡¢´Ù¤ê¤ä¤¹¤¤¥ß¥¹¤Ê¤Î¤Ç¤¹¤¬¡£
Dir´Ø¿ô¤Ï¡¢¥Õ¥¡¥¤¥ë¤ä¥Õ¥©¥ë¥À¤ò¸¡º÷¤¹¤ë´Ø¿ô¤Ç¤¹¤Í¡£
Î㤨¤Ð¡¢
Fname=Dir("FoluderA¡ïA.xls")
¤Î¤è¤¦¤Ë½ñ¤¤¤¿¾ì¹ç¡¢
FoluderA¤Î¥Õ¥©¥ë¥À¤ÎÃæ¤ËA.xls¤È¸À¤¦¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ì¤Ð¡¢
Fname¤Ë¤Ï"A.xls"¤È¸À¤¦Ê¸»úÎó¤¬ÊÖ¤µ¤ì¡¢
¸ºß¤·¤Ê¤¤¾ì¹ç¤Ï""¡ÊŤµ¥¼¥í¤Îʸ»úÎó¡Ë¤¬ÊÖ¤ê¤Þ¤¹¡£
FoluderA¤ÎÃæ¤Ë01A.xls¡¢02A.xls¡¢03A.xls¡¦¡¦¡¦¤È¸À¤¦¤è¤¦¤Ë¡¢
¡»¡»A.xls¤È¸À¤¦¥Õ¥¡¥¤¥ë¤¬Ê£¿ô¤¢¤ê¡¢¤½¤ì¤¾¤ì¤Î¥Õ¥¡¥¤¥ë¤ËÂФ·¡¢
½èÍý¤ò¹Ô¤¤¤¿¤¤¤È¸À¤¦¾ì¹ç¤Ï¡¢¥ï¥¤¥ë¥É¥«¡¼¥É¡Ê¾®Ê¸»úȾ³Ñ¤Î¡ö¡Ë¤ò»È¤¦ÊýË¡¤¬¤¢¤ê¤Þ¤¹¡£
Fname=Dir("FoluderA¡ï¡öA.xls")
¤³¤Î¤è¤¦¤Ë½ñ¤¯¤È¡¢¤Þ¤º¡¢01A.xls¡Ê¤È¸À¤¦¤«ºÇ½é¤Ë¸¡º÷¤µ¤ì¤¿¤Ò¤È¤Ä¡Ë¤¬Ê֤äƤ¤Þ¤¹¡£
»Ä¤ê¤Î¥Õ¥¡¥¤¥ë¤ò¸¡º÷¤·¤¿¤¤¾ì¹ç¤Ï¡¢
Fname=Dir
¤Î¤è¤¦¤Ë°ú¿ô¤òÉÕ¤±¤Ê¤¤¤Ç½ñ¤¯¤È¡¢¼¡¤Î02A.xls¤¬¸¡º÷¤µ¤ì¤Þ¤¹¡£
¤µ¤é¤ËFname=Dir¤È½ñ¤±¤Ð¡¢03A.xls¤ò¸¡º÷¡¦¡¦¡¦¤È¸À¤¦¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¤Ä¤Þ¤ê°ú¿ô¤òÉÕ¤±¤Ê¤¤Dir´Ø¿ô¤ÏľÁ°¤Ë»ÈÍѤ·¤¿Dir´Ø¿ô¤Î°ú¿ô¤¬»È¤ï¤ì¤ë¤È¸À¤¦»ö¤Ç¤¹¤Í¡£
¤·¤¿¤¬¤Ã¤Æ¡¢Î㤨¤Ð¼¡¤Î¤è¤¦¤Ë½ñ¤¤Þ¤¹¤È¡¢
Fname¤Ë""""¡ÊŤµ¥¼¥í¤Îʸ»úÎó¡Ë¤¬ÊÖ¤ë¤Þ¤ÇLoop¤·¤Þ¤¹¤Î¤Ç¡¢
FoluderAÆâ¤Î¡»¡»A.xls¤È¸À¤¦¥Õ¥¡¥¤¥ë¤¹¤Ù¤Æ¤ËÂФ·¤Æ¡¢
Ʊ¤¸½èÍý¤¬½ÐÍè¤Þ¤¹¡£
Sub Sample()
Dim FName as String
Fname=Dir("FoluderA¡ï¡öA.xls")
¡¡¡¡¡¡ Do Until Fname=""
¡¡¡¡ Call SumpleSub(FName)
FName=Dir ¡¦¡¦¡¦¡
Loop
End Sub
Sub SumpleSub(HikisuFname as String)
HikisuFname ¤Î¥Õ¥¡¥¤¥ë¤ËÂФ¹¤ë½èÍý
End Sub
¤È¤³¤í¤Ç¡¢¤³¤³¤Çº£Æü¤Î¥Æ¡¼¥Þ¤Ê¤Î¤Ç¤¹¤¬¡¢
Ãí°Õ¤¬É¬ÍפʤΤϡ¢SumpleSub¤ÎÃæ¤Ç¤â¡¢
Dir´Ø¿ô¤ò»È¤Ã¤¿¾ì¹ç¤Ç¤¹¡£
Î㤨¤ÐFoluderB¤È¸À¤¦¥Õ¥©¥ë¥À¤Ë¤âƱ¤¸¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¾ì¹ç¤Ë¡¢
²¿¤«¤ò¤¹¤ë¤È¸À¤¦¤è¤¦¤Ê¾ì¹ç¡¢
Sub SumpleSub(HikisuFname as String)
¡¡¡¡¡¡Dim Fname as String
Fname=Dir("FoluderB¡ï" & HikiSuFname)
If FName <> "" then
¡ÖFoluderB¤ËHikiSuFname¤¬Â¸ºß¤¹¤ë¾ì¹ç¤Î½èÍý¡×
¡¡¡¡ End If¡¡
End Sub
¤µ¤Æ¡¢»ä¤Î¸À¤¤¤¿¤¤»ö¤Ï¤â¤¦¤ªÊ¬¤«¤ê¤È»×¤¤¤Þ¤¹¤¬¡¢
¤³¤Î¤è¤¦¤Ë½ñ¤¯¤È¡¢
¾åµ¡¤Î°ú¿ô¤Ê¤·¤ÎDir´Ø¿ô¤Î°ú¿ô¤Ï¡¢²¿¤ò°ú¤·Ñ¤°¤«¤È¸À¤¦¤È¡¢
SumpleSub¤ÎÃæ¤Î¡¢("FoluderB¡ï" & HikiSuFname)¤Ë¤Ê¤ë¡¢
¤È¸À¤¦»ö¤Ç¤¹¡£Ä¾Á°¤ÎDir´Ø¿ô¤ò°ú¤·Ñ¤°¤Î¤Ç¤¹¤«¤éÅöÁ³¤Ç¤¹¤Í¡£
Dir´Ø¿ô¤Ï½ñ¤¤ä¤¹¤¤´Ø¿ô¤Ê¤Î¤Ç¤è¤¯»È¤¤¤Þ¤¹¤¬¡¢
»þ¤Ë¤³¤¦¸À¤¦Íî¤È¤··ê¤â¤¢¤ë¤Î¤ÇÃí°Õ¤¬É¬ÍפǤ¹¡£
¤³¤Îµ»ö¤Ø¤Î¥È¥é¥Ã¥¯¥Ð¥Ã¥¯URL
http://trackback.blogsys.jp/livedoor/katsuyausami/52035059