SP said:
I have a .BAS file with a macro module that I can manually import
into the Normal project in VB Editor.
I'd like to automate this process. Can someone give me the codes
that will do this ?
Thank you
Steve
Here you go:
Public Sub ImportModule()
' requires security setting to
' "Trust access to Visual Basic"
' and reference to VBA Extensibility
Dim oModule As VBComponent
Dim BasFile As String
On Error GoTo Bye
BasFile = "C:\docs\exported.bas"
Set oModule = _
NormalTemplate.VBProject.VBComponents.Import( _
FileName:=BasFile)
oModule.Name = "Imported"
NormalTemplate.Save
Exit Sub
Bye:
MsgBox "Import failed - error " & _
Err.Number & vbCr & Err.Description
End Sub
Change the path/filename of the .bas file and the name given to the imported
module to suit your needs. Before running the macro, be sure to take care of
the details mentioned in the comments.