Excel VBAã§ã¢ã¸ã¥ã¼ã«ãã¨ã¯ã¹ãã¼ãããã³ã¼ã
ãã®ãã¼ã¸ã®ã³ã¼ãã®ããã使ãããããã¼ã¸ã§ã³ãMoonDoldoããã®ãµã¤ãã® http://gyahahaha.s51.coreserver.jp/DoldoWorkz/?Excel%E3%83%9E%E3%82%AF%E3%83%AD/VBA%E3%83%9E%E3%82%AF%E3%83%AD%E3%81%AE%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%E3%82%92%E3%82%A8%E3%82%AF%E3%82%B9%E3%83%9D%E3%83%BC%E3%83%88 ã«ããã¾ãã
Excelã®ã¯ã¼ã¯ããã¯ãã½ã¼ã¹ã³ã¼ã管çã·ã¹ãã ã§ç®¡çãããããã
ç§ã¯Excelï¼VBAã§ä½ã£ãã¢ããªã±ã¼ã·ã§ã³ãã½ã¼ã¹ã³ã¼ã管çã·ã¹ãã ã«æ ¼ç´ãã¦ç®¡çãããã¨ãããã¾ããExcelã®ã¯ã¼ã¯ããã¯ã¯ãã¤ããªã»ãã¡ã¤ã«ãªã®ã§ãã¼ã¸ã§ã³éã®å·®åãè¦ãã®ãé£ãããã©ã®ããã«ããã°ãã¾ã管çã§ããã®ãæ©ãã§ãã¾ããã
Subversionã§ç®¡çãããªããExcelã®ã¯ã¼ã¯ã·ã¼ãã®å·®åã¯TortoiseSVNã§è¡¨ç¤ºãããã¨ãã§ãã¾ããVBAã®ã³ã¼ãã®å·®åã¯æ¬¡ã®ããã«ããã°ç®¡çã§ãããã¨ã«æ°ãã¤ãã¾ããã
- VBAã®ã³ã¼ããããã¹ããã¡ã¤ã«ã«åºåããã
- Excelã®ã¯ã¼ã¯ããã¯ã¨ä¸ç·ã«ããã¹ããã¡ã¤ã«ããªãã¸ããªã«å ¥ããã
ã³ã¼ãã®å ¥ã£ãããã¹ããã¡ã¤ã«ã調ã¹ããã¨ã§ãã³ã¼ãã«ãã¤ã©ã®ãããªå¤æ´ãããã®ãããããããã«ãªãã¾ããããã§ãã³ãããã®ç´åã«æ¯åã¢ã¸ã¥ã¼ã«ãããã¹ããã¡ã¤ã«ã«ã¨ã¯ã¹ãã¼ããããã¨ã«ãã¾ããã次ã®æé ã§ã¨ã¯ã¹ãã¼ãã§ãã¾ãã
- Excelã®Visual Basic Editorï¼VBEï¼ã表示ããã
- ããã¸ã§ã¯ãã¨ã¯ã¹ããã¼ã©ã¼ã§ã¢ã¸ã¥ã¼ã«åãå³ã¯ãªãã¯ãã[ãã¡ã¤ã«ã®ã¨ã¯ã¹ãã¼ã]ãã¯ãªãã¯ããã
- ããã¡ã¤ã«ã®ã¨ã¯ã¹ãã¼ãããã¤ã¢ãã°ã表示ãããã®ã§ããã¡ã¤ã«åãå ¥åãã[ä¿å]ãã¯ãªãã¯ããã
ãããæ¯åæä½æ¥ã§ãã£ã¦ããã®ã§ãããé¢åã«ãªã£ãã®ã§ãã¢ã¸ã¥ã¼ã«ããã¡ã¤ã«ã«ã¨ã¯ã¹ãã¼ãããã³ã¼ããä½ãã¾ãããåèã¾ã§ã«æ¥è¨ã«è¨è¼ãã¾ãã
ã¢ã¸ã¥ã¼ã«ãã¨ã¯ã¹ãã¼ãããã³ã¼ã
Option Explicit Public Sub ExportModules() 'ç¾å¨ã®ã¯ã¼ã¯ããã¯ã®ã¢ã¸ã¥ã¼ã«ãã¨ã¯ã¹ãã¼ããã Dim targetModule As VBComponent Dim outputPath As String Dim fileExt As String outputPath = ActiveWorkbook.Path For Each targetModule In ActiveWorkbook.VBProject.VBComponents fileExt = GetExtFromModuleType(targetModule.Type) If fileExt <> "" Then ExportModuleWithExt targetModule, outputPath, fileExt Debug.Print "Save " & targetModule.Name End If Next End Sub Private Function GetExtFromModuleType(aType As Integer) As String 'æå®ãããã¢ã¸ã¥ã¼ã«ã»ã¿ã¤ãã«å¯¾å¿ããæ¡å¼µåãè¿ã Select Case aType Case vbext_ct_StdModule GetExtFromModuleType = "bas" Case vbext_ct_ClassModule, vbext_ct_Document GetExtFromModuleType = "cls" Case vbext_ct_MSForm GetExtFromModuleType = "frm" End Select End Function Private Sub ExportModuleWithExt(aModule As VBComponent, Path As String, Ext As String) 'æå®ãããã¢ã¸ã¥ã¼ã«ãã¨ã¯ã¹ãã¼ããã Dim filePath As String filePath = Path & "\" & aModule.Name & "." & Ext aModule.Export filePath End Sub
ExportModulesããã·ã¼ã¸ã£ãå®è¡ããã¨ãã¢ã¸ã¥ã¼ã«ãæ ¼ç´ãããã¡ã¤ã«ããç¾å¨ã®ã¯ã¼ã¯ããã¯ã¨åãå ´æã«åºåãã¾ããåºåããã¢ã¸ã¥ã¼ã«ã¯ä»¥ä¸ã®ç¨®é¡ã®ãã®ã§ãã
- æ¨æºã¢ã¸ã¥ã¼ã«
- ã¯ã©ã¹ã¢ã¸ã¥ã¼ã«
- ã¯ã¼ã¯ã·ã¼ãã®ã¯ã©ã¹ã¢ã¸ã¥ã¼ã«
åºåããããã¡ã¤ã«ã®ååã¯ããªãã¸ã§ã¯ãåï¼æ¡å¼µåã«ãªãã¾ããæ¡å¼µåã¯æ¨æºã¢ã¸ã¥ã¼ã«ã®å ´åã¯âbasâãã¯ã©ã¹ã¢ã¸ã¥ã¼ã«ã®å ´åã¯âclsâã«ãªãã¾ãã
åºåæã«ã¯ãåºåãããªãã¸ã§ã¯ãã®ååããSave ãªãã¸ã§ã¯ãåãã®å½¢ã§ã¤ããã£ã¨ã¤ãã»ã¦ã£ã³ãã¦ã«è¡¨ç¤ºãã¾ãã
ã³ã¼ãä¸ã§ä½¿ã£ã¦ãã以ä¸ã®ååã¯ãMicrosoft Visual Basic for Application Extensibility 5.3ãã§å®£è¨ããã¦ãã¾ãã
- VBComponent
- vbext_ct_StdModule
- vbext_ct_ClassModule
- vbext_ct_Document
ã¢ã¸ã¥ã¼ã«ãã¨ã¯ã¹ãã¼ãããã³ã¼ããExcelã«çµã¿è¾¼ã
次ã®æé ã§Excelã«çµã¿è¾¼ãã§ä½¿ãã¾ãã
1. Excel VBEã®[ãã¼ã«]-[åç
§è¨å®]ã§ãMicrosoft Visual Basic for Application Extensibility 5.3ãã«ãã§ãã¯ãå
¥ãã¾ãã
2. [æ¿å
¥]-[æ¨æºã¢ã¸ã¥ã¼ã«]ã§æ°ããæ¨æºã¢ã¸ã¥ã¼ã«ãä½æããä¸è¨ã®ã³ã¼ããã³ãã¼ï¼ãã¼ã¹ãã§è¨å
¥ãã¾ãã
3. ã¢ã¸ã¥ã¼ã«ãé©å½ãªååï¼èªåã®å ´åã¯ModuleExporterï¼ã§ä¿åãã¾ãã
4. 以ä¸ã®ã©ããã®æ¹æ³ã§ExportModulesããã·ã¼ã¸ã£ãå®è¡ãã¾ãã
4-1 ã¤ããã£ã¨ã¤ãã¦ã£ã³ãã¦ã§âExportModulesâã¨å
¥åããEnterãã¼ãå
¥åãã¾ãã
4-2 âPublic Sub ExportModules()âã¨æ¸ããã¦ããè¡ã«ã«ã¼ã½ã«ãåãããF5ãã¼ãæ¼ãã¾ããã¾ãã¯ãF5ãã¼ã®ä»£ããã«[å®è¡]-[Sub/ã¦ã¼ã¶ã¼ãã©ã¼ã ã®å®è¡]ãã¯ãªãã¯ãããããSub/ã¦ã¼ã¶ã¼ãã©ã¼ã ã®å®è¡]ãã¿ã³ãã¯ãªãã¯ãã¾ãã
ããã§ä½åº¦ã§ãæ軽ã«ã¢ã¸ã¥ã¼ã«ãã¨ã¯ã¹ãã¼ãã§ããããã«ãªãã¾ããã
ï¼è¿½è¨ 2010/02/18ï¼
ãããã¯ããå®è¡ã§ããªãã¨ãã¯ã次ã®ããã«ãã¦ãã ããï¼ã³ã¡ã³ãã§æãã¦ããã ãã¾ããããããã¨ããããã¾ããï¼
- [ãã¼ã«]-[ãã¯ã]-[ã»ãã¥ãªãã£]ãã¯ãªãã¯
- [ä¿¡é ¼ã®ãããçºè¡å ]ã¿ãã®[Visual Basicããã¸ã§ã¯ãã¸ã®ã¢ã¯ã»ã¹ãä¿¡é ¼ãã]ãã§ãã¯ããã¯ã¹ããªã³ã«ãã
ï¼è¿½è¨ 2010/02/23ï¼
Office2007ã§ãå®è¡æã¨ã©ã¼ 1004ãããã°ã©ãã³ã°ã«ãã Visual Basic ããã¸ã§ã¯ãã¸ã®ã¢ã¯ã»ã¹ã¯ä¿¡é ¼æ§ã«æ¬ ãã¾ããã¨åºã¦æ¢ã¾ã£ã¦ãã¾ãå ´åã«ã¯ã次ã®ããã«ãã¦ãã ããï¼ã³ã¡ã³ãã§æãã¦ããã ãã¾ããããããã¨ããããã¾ããï¼
- Office 2007 ãèµ·åã㦠[Office ãã¿ã³] ãã¯ãªãã¯
- [Excelã®ãªãã·ã§ã³] ãã¯ãªãã¯
- [ã»ãã¥ãªã㣠ã»ã³ã¿ã¼] ãã¯ãªãã¯
- [ã»ãã¥ãªã㣠ã»ã³ã¿ã¼ã®è¨å®] ãã¯ãªãã¯
- [ãã¯ãã®è¨å®] ãã¯ãªãã¯
- [VBA ããã¸ã§ã¯ã ãªãã¸ã§ã¯ã ã¢ãã«ã¸ã®ã¢ã¯ã»ã¹ãä¿¡é ¼ãã] ãã§ã㯠ããã¯ã¹ããªã³ã«ãã