A family of Microsoft word processing software products for creating web, email, and print documents.
You can use code like:
Sub InsertVBComponent(ByVal Doc As Document, ByVal CompFileName As String)
' inserts the contents of CompFileName as a new component in wb
' CompFileName must be a valid VBA component suited for import (an exported VBA component)
If Dir(CompFileName) <> "" Then ' source file exist
On Error Resume Next ' ignores any errors if the project is protected
Doc.VBProject.VBComponents.Import CompFileName ' inserts component from file
On Error GoTo 0
End If
Set Doc = Nothing
End Sub
called with:
InsertVBComponent ActiveDocument, "C:\FolderName\Filename.bas"
Note: To use the above procedures, you need to set a reference to Microsoft Visual Basic For Applications Extensibility and the user running the code must grant access to VBA object model (seehttp://support.microsoft.com/kb/282830).