有没有人知道从许多Excel文档导出VBA代码的方法,以便可以将代码添加到subversion存储库中?无需手动打开每个文档并导出代码.
你会在这里找到一个工具:
http://www.pretentiousname.com/excel_extractvba/index.html
这是一个自动化excel的VBS脚本.您可以根据自己的需要进行修改 - 请注意它并不完美(请参阅网页了解警告).
option explicit Const vbext_ct_ClassModule = 2 Const vbext_ct_Document = 100 Const vbext_ct_MSForm = 3 Const vbext_ct_StdModule = 1 Main Sub Main Dim xl Dim fs Dim WBook Dim VBComp Dim Sfx Dim ExportFolder If Wscript.Arguments.Count <> 1 Then MsgBox "As the only argument, give the FULL path to an XLS file to extract all the VBA from it." Else Set xl = CreateObject("Excel.Application") Set fs = CreateObject("Scripting.FileSystemObject") xl.Visible = true Set WBook = xl.Workbooks.Open(Trim(wScript.Arguments(0))) ExportFolder = WBook.Path & "\" & fs.GetBaseName(WBook.Name) fs.CreateFolder(ExportFolder) For Each VBComp In WBook.VBProject.VBComponents Select Case VBComp.Type Case vbext_ct_ClassModule, vbext_ct_Document Sfx = ".cls" Case vbext_ct_MSForm Sfx = ".frm" Case vbext_ct_StdModule Sfx = ".bas" Case Else Sfx = "" End Select If Sfx <> "" Then On Error Resume Next Err.Clear VBComp.Export ExportFolder & "\" & VBComp.Name & Sfx If Err.Number <> 0 Then MsgBox "Failed to export " & ExportFolder & "\" & VBComp.Name & Sfx End If On Error Goto 0 End If Next xl.Quit End If End Sub
-亚当
在过去的几年里,我成功地使用了这个来导出我的代码并保存它.我可以确认它在Office 2003,2007中有效.我认为它也适用于2000.
http://www.codeproject.com/KB/office/SourceTools.aspx