首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Microsoft Access导出代码

从Microsoft Access导出代码
EN

Stack Overflow用户
提问于 2010-05-08 22:49:05
回答 4查看 4.9K关注 0票数 3

有没有办法将Microsoft Access代码批量导出到文件?我知道我可以一次导出一个文件,但是有数百个文件,我会在这里呆上一整天。是否没有“全部导出”或多选导出?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-05-09 04:14:35

要将所有代码输出到桌面,包括来自窗体和报表的代码,您可以将此代码粘贴到一个标准模块中,然后通过按F5键或使用F8单步执行来运行它。您可能希望先填写桌面文件夹的名称。

代码语言:javascript
复制
   Sub AllCodeToDesktop()
   ''The reference for the FileSystemObject Object is Windows Script Host Object Model
   ''but it not necessary to add the reference for this procedure.

   Dim fs As Object
   Dim f As Object
   Dim strMod As String
   Dim mdl As Object
   Dim i As Integer

   Set fs = CreateObject("Scripting.FileSystemObject")

   ''Set up the file.
   ''SpFolder is a small function, but it would be better to fill in a
   ''path name instead of SpFolder(Desktop), eg "c:\users\somename\desktop"
   Set f = fs.CreateTextFile(SpFolder(Desktop) & "\" _
       & Replace(CurrentProject.Name, ".", "") & ".txt")

   ''For each component in the project ...
   For Each mdl In VBE.ActiveVBProject.VBComponents
       ''using the count of lines ...
       i = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.CountOfLines
       ''put the code in a string ...
       If i > 0 Then
          strMod = VBE.ActiveVBProject.VBComponents(mdl.Name).codemodule.Lines(1, i)
       End If
       ''and then write it to a file, first marking the start with
       ''some equal signs and the component name.
       f.writeline String(15, "=") & vbCrLf & mdl.Name _
           & vbCrLf & String(15, "=") & vbCrLf & strMod
   Next

   ''Close eveything
   f.Close
   Set fs = Nothing
   End Sub

若要获取特殊文件夹,可以使用Microsoft提供的列表。

枚举特殊文件夹:http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_higv.mspx?mfr=true

来自:http://wiki.lessthandot.com/index.php/Code_and_Code_Windows

票数 1
EN

Stack Overflow用户

发布于 2010-05-09 20:12:38

您可以在根本不编写任何代码的情况下完成此操作。从菜单中选择tools->analyze->database documenter。

这将为您提供一系列打印代码的选项。然后,您可以在查看报告时将其发送到您的PDF打印机(如果您有打印机)。或者,简单地打印到文本文件打印机。或者,您甚至可以单击报告菜单栏中的word选项,结果将发送到word

数据库文档管理器提供了打印所有代码的功能,包括表单中的代码。

因此,代替一些建议的代码示例,您可以在根本不编写任何代码的情况下执行此操作。一定要使用documenter中的其他选项。文档员将为数据库中的每个单独的属性和对象生成大量打印信息。因此,如果您不取消选中某些选项,那么您将很容易清空装满纸张的全尺寸打印机托盘。因此,这个文档生成器会产生大量的打印输出。

票数 5
EN

Stack Overflow用户

发布于 2010-05-08 23:17:53

界面中没有任何东西可以一次导出多个模块。

您可以轻松编写自己的“全部导出”等效项:

代码语言:javascript
复制
Public Sub ExportModules()
Const cstrExtension As String = ".bas"
Dim objModule As Object
Dim strFolder As String
Dim strDestination As String

strFolder = CurrentProject.Path

For Each objModule In CurrentProject.AllModules
    strDestination = strFolder & Chr(92) & objModule.Name & cstrExtension
    Application.SaveAsText acModule, objModule.Name, strDestination
Next objModule
End Sub
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2794480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档