Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting Excel Modules to Word 1

Status
Not open for further replies.

VBAva

Programmer
Jul 29, 2003
87
0
0
IE
Hello

I was just wondering if anyone has a handy bit of code that would export the code from a VB project in Excel into Word to make it easier to print??

between modules and forms there are about 30 different parts to the code so if i exported then imported them all manually it could take some time.

Thank you in Advance
Ava
:)
 
With reference to 'Microsoft Visual Basic for Applications Extensibility 5.3' (VBIDE library):
[tt]Sub ExportCode()
Dim wdApp As New Word.Application
Dim wdDoc As Word.Document
Dim vbComp As VBComponent, cModule As VBIDE.CodeModule
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add
With wdDoc
For Each vbComp In ThisWorkbook.VBProject.VBComponents
Set cModule = vbComp.CodeModule
.Content.InsertAfter vbComp.Name
If cModule.CountOfLines > 0 Then
.Content.InsertAfter cModule.Lines(1, cModule.CountOfLines)
End If
.Paragraphs.Add
.Paragraphs.Add
Next
End With
End Sub[/tt]

A tool for printing code:

combo
 
Hi Cambo

thanks for the code but i cant seem to get it to work :-(
i have the Microsoft Visual Basic for Applications Extensibility 5.3 reference added but i get

'User-defined type not defined' error

i am not too sure how to get it working, sorry
 
Sorry, I missed to mention that the reference to Microsoft Word Object Library is also necessary.

combo
 
Thanks, that works great, have a star :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top