Sub SaveCodesToPDF()
Dim wb As Workbook
Dim WordApp As Word.Application
Dim TempDoc As Word.DOCUMENT
Dim VBP As VBIDE.VBProject
Dim VBC As VBIDE.VBComponent
Dim Data As String
Dim LineCount As Long
For Each wb In Workbooks
On Error Resume Next
Set VBP = ActiveWorkbook.VBProject
On Error GoTo 0
If VBP Is Nothing Then
MsgBox "Your security settings do not allow this macro to run."
Exit Sub
End If
CDR = Replace(wb.Name, ".xlsm", "")
oName = CDR & " Codes"
Set WordApp = CreateObject("Word.Application")
Set TempDoc = WordApp.DOCUMENTS.Add
Data = ""
For Each VBC In VBP.VBComponents
With VBC.CodeModule
LineCount = .CountOfLines - .CountOfDeclarationLines
End With
If LineCount > 0 Then
With VBC.CodeModule
Data = WorksheetFunction.Rept("=", 60) & vbCrLf
Data = Data & "VB Component: " & VBC.Name & vbCrLf
Data = Data & .Lines(1, .CountOfLines) & vbCrLf
End With
TempDoc.Content.InsertAfter Data
Data = ""
End If
Next VBC
With TempDoc.Content.Font
.Name = "Times New Roman"
.Bold = False
.Size = 8
End With
With TempDoc.Content.PageSetup
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
End With
With TempDoc.Content.ParagraphFormat
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
End With
TempDoc.ExportAsFixedFormat "S:\SERVICE\Repair Shop CDRs\CDR Templates\CDR Codes Test\" & oName & ".pdf", wdExportFormatPDF
'TempDoc.SaveAs "S:\SERVICE\Repair Shop CDRs\CDR Templates\CDR Codes Test\" & oName
TempDoc.Close savechanges:=False
WordApp.Quit
Next wb
End Sub