Need to do housecleaning on my macros

E

Ed from AZ

Having been migrated to a new system, it's time for a bit of
housecleaning. I've got macros I wrote for one use and never used
again, and I can't find some I've come to rely on.

So my idea is to export all the modules from all my template projects
and import them into one new template to use as an add-in. Along the
way, I can evaluate whether the macro is something I still need or can
do without.

Is there an easy and automated way to export all modules from a
project?
Is there an easy and automated way to print these modules?
What is the practical size limit of an add-in?

I'm using Word 2007 and Vista.
Ed
 
G

Greg Maxey

Maybe you can adapt these procedures to your specific needs:

Sub MacroList()
Dim oRng As Word.Range
Dim oProject As VBProject
Dim strName As String
Dim i As Long
Dim lngLineNumber As Long
Dim j As Long
Dim lngLineCount As Long
Set oProject = ActiveDocument.VBProject
Set oRng = ActiveDocument.Range
oRng.InsertAfter "The project Name is: " & oProject.Name & "." & vbCr
With oProject
For i = 1 To .VBComponents.Count
oRng.InsertAfter vbTab & "Component " & i & " is: " _
& .VBComponents(i).Name & vbCr
lngLineCount = .VBComponents(i).CodeModule.CountOfLines
If lngLineCount > 3 Then
strName = ""
lngLineNumber = 1
j = 1
Do While strName = ""
strName = .VBComponents(i).CodeModule.ProcOfLine(lngLineNumber,
vbext_pk_Proc)
lngLineNumber = lngLineNumber + 1
Loop
oRng.InsertAfter vbTab & vbTab & "The procedure(s) in this component
are:" & vbCr _
& vbTab & vbTab & vbTab & "Procedure " & j & ": " & strName & vbCr
For lngLineNumber = lngLineNumber To lngLineCount
If .VBComponents(i).CodeModule.ProcOfLine(lngLineNumber,
vbext_pk_Proc) <> strName Then
j = j + 1
strName = .VBComponents(i).CodeModule.ProcOfLine(lngLineNumber,
vbext_pk_Proc)
oRng.InsertAfter vbTab & vbTab & vbTab & "Procedure " & j & ": "
& strName & vbCr
End If
Next
Else
oRng.InsertAfter vbTab & vbTab & "There are no procedures in this
component." & vbCr
End If
Next
End With
Set oRng = Nothing
Set oProject = Nothing
End Sub

Sub ProjectModuleExport()
Dim oProject As VBProject
Dim i As Long
Set oProject = ActiveDocument.VBProject
With oProject
For i = 1 To .VBComponents.Count
MsgBox .VBComponents(i).Name
Select Case .VBComponents(i).Type
Case vbext_ct_StdModule, vbext_ct_ClassModule, vbext_ct_MSForm
.VBComponents(i).Export ("C:\" & .Name & "_" & .VBComponents(i).Name
& ".bas")
Case Else
End Select
Next
End With
End Sub

Sub CopyMacroCodeToDoc()
Dim oRng As Word.Range
Dim oProject As VBProject
Dim i As Long
Set oProject = ActiveDocument.VBProject
Set oRng = ActiveDocument.Range
oRng.InsertAfter oProject.Name & "." & vbCr & vbCr
With oProject
For i = 1 To .VBComponents.Count
oRng.InsertAfter .VBComponents(i).CodeModule.Lines(1,
..VBComponents(i).CodeModule.CountOfLines)
Next i
End With
Set oRng = Nothing
Set oProject = Nothing
End Sub
 

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