I've been tasked with creating a VBA based system that will allow me to insert department specific documentation comment codes into a VBA based program and then later extract these later date.The program does this by temporarily inserting 2 VBA modules into the target project and then running the contained functions. This on it's own functions properly and the comments are inserted/extracted using VBA.
However I find myself at a loss for inserting the modules into an excel based project from my access based insertion project. I've been importing the module to the targeted access project using this function:
Public Function InsertVADER(strTestPath As String, ProgramType As String) As Boolean
'//Insert VADER into the target program
On Error GoTo errjordan
Dim obj As AccessObject '//Create instance of Access Application object.
If ProgramType = "Access" Then
''//Transfer Modules to target project.
For Each obj In CurrentProject.AllModules
DoCmd.TransferDatabase acExport, "Microsoft Access", strTestPath, acModule, obj.Name, obj.Name & "_TMP", False
Next obj
'//Set and open target project
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase strTestPath, False
'//SEt to visible. If the project has an auto exec that will usurp this project. You will
appAccess.Visible = True
'//Open the vader module. If there is an auto run macro this will cause it to show
appAccess.DoCmd.OpenModule ("VADER_TMP")
ElseIf ProgramType = "Excel" Then
'//Run Excel routine
For Each obj In CurrentProject.AllModules
'DoCmd.TransferDatabase acExport, "Microsoft Excel", strTestPath, acModule, obj.Name, obj.Name & "_TMP", False
Next obj
End If
'//Indicate function sucess
InsertVADER = True
Exit Function 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
errjordan:
If Err.Number = 2501 Then
MsgBox "Project cannot be locked for viewing. Please unlock and save project before using this tool"
Err.Clear
InsertVADER = False
ElseIf Err.Number = 29045 Or Err.Number = 7866 Then
MsgBox "This file is not compatible with VADER. Please convert the project to a useable format before using this tool."
Err.Clear
InsertVADER = False
Else
Err.Raise Err.Number
End If
End Function
StrtestPath passes the file path of the target project and programtype specifies what kind of project I've selected. Both are set in an external project.
Is there a VBA based solution that will allow me to:
- Import the modules defined by the CurrentProject.allModules into the targeted Excel project from access
- Remove the modules from the target Excel Project once run