Incomplete results mass exporting Access VBA modules (1 Viewer)

mdlueck

Sr. Application Developer
Local time
Today, 05:47
Joined
Jun 23, 2011
Messages
2,631
Greetings,

I have tried two methods to export VBA modules. Neither for me produce complete hidden headers that the manual export user interface includes. This results in VBA not being able to import them successfully.

I have tried the following two VBA implementations:

1) VCS code originated from https://github.com/timabell/msaccess-vcs-integration/

which uses this method to extract out from Access / VBA the individual module files:

Application.SaveAsText obj_type_num, obj_name, file_path

2) When I discovered the error with this, then I found this other way to do "the same thing"...

Code:
  Set appAccess = CreateObject("Access.Application")
  appAccess.OpenCurrentDatabase (strAccessDBFullFilename)

  Set objProj = appAccess.VBE.ActiveVBProject

  If objProj Is Nothing Then
    Debug.Print "ExportModule_ExportAllModules objProj was Nothing"
    GoTo Exit_ExportModule_ExportAllModules
  End If

  For Each objComponent In objProj.VBComponents
    'Export the files as *.bas files
    objComponent.Export strAccessModuleExportFullPath & objComponent.Name & ".bas"
  Next objComponent
The issue both of these automated methods have:

Manually exported via the VBA editor has the following header lines before the VBA code:

Code:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "clsObjProjectsTbl"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
When I use either of these VBA automated ways of exporting the same module, the resulting export file only has these header lines:

Code:
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
How do I get around this bug and successfully export via VBA automation?

I am thankful,
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:47
Joined
Oct 29, 2018
Messages
21,357
Hi Michael. I haven't done anything like this before, so although I just gave it a try, I cannot promise if this is the correct way to do it. However, when I executed the following command in the Immediate Window, I got the same output as if I had done it manually.
Code:
Application.VBE.SelectedVBComponent.Export CurrentProject.Path & "\test1.txt"
Since the above was basically done "manually" because I had the class module selected in the VBE window, I then executed the following line just to see if it can be done without selecting the module first.
Code:
Application.VBE.ActiveVBProject.VBComponents.Item(5).Export CurrentProject.Path & "\test2.txt"
This time, it worked as intended. It didn't matter which module I had selected, it always exports the specific item I entered in the code. Hopefully, you can use this. But if you find a better way, please let us know. Thanks.
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:47
Joined
Sep 21, 2011
Messages
14,038
As do I, but I get none of those headers at all.?:confused:

My first few lines.

Code:
Attribute VB_Name = "Module2"
Option Compare Database
Public Function Previous(strFormName As String, strFieldName As String)
 

mdlueck

Sr. Application Developer
Local time
Today, 05:47
Joined
Jun 23, 2011
Messages
2,631
Odd... my #2 version of the module exporter above this evening IS exporting all of the header lines. Perhaps I just forgot to re-export all the modules after writing the #2 version, thus thought it defective as well.

I am thankful,
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:47
Joined
Oct 29, 2018
Messages
21,357
Odd... my #2 version of the module exporter above this evening IS exporting all of the header lines. Perhaps I just forgot to re-export all the modules after writing the #2 version, thus thought it defective as well.

I am thankful,
Hi Michael. Glad to hear you got it sorted out. Good luck!
 

Users who are viewing this thread

Top Bottom