importing .bas

S

SP

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
 
J

Jay Freedman

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.
 
S

SP

Mucho Gracias
Steve

Jay Freedman said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top