Private Const wdHeaderFooterEvenPages = 3
Private Const wdHeaderFooterFirstPage = 2
Private Const wdHeaderFooterPrimary = 1
Private Const wdSeekMainDocument = 0
Private Const wdSeekPrimaryHeader = 1
Private Const wdSeekFirstPageHeader = 2
Private Const wdSeekEvenPagesHeader = 3
Private Const wdSeekPrimaryFooter = 4
Private Const wdSeekFirstPageFooter = 5
Private Const wdSeekEvenPagesFooter = 6
Private Const wdSeekFoonotes = 7
Private Const wdSeekEndNotes = 8
Private Const wdSeekCurrentPageHeader = 9
Private Const wdSeekCurrentPageFooter = 10
Private Const wdReplaceNonel = 0
Private Const wdReplaceOne = 1
Private Const wdReplaceAll = 2
Private Const wdFindStop = 0
Private Const wdFindContinue = 1
Private Const wdFindAsk = 2
Private Const wdCollapseStart = 0
Private Const wdCollapseEnd = 1
Public Class WordCleaner
m_word As Variant
Public Sub New(wordApp As Variant)
Set m_word = wordApp
End Sub
Public Sub ConvertFootNotes()
Dim temp_range As Variant
Dim notes_text As String
notes_text = ""
Dim footnote_index As Integer
Dim footnote_count As Integer
footnote_count = m_word.ActiveDocument.Footnotes.Count
For footnote_index = 1 To footnote_count
notes_text = notes_text & "(" & footnote_index & ") " & _
GetFootNoteText(footnote_index)
Set temp_range = m_word.ActiveDocument.Footnotes(footnote_index).Reference
Call temp_range.Collapse(wdCollapseEnd)
temp_range.Text = "(" & footnote_index & ")"
Next
Call DeleteFootNotes
Call InsertEndNotes(notes_text)
End Sub
Private Function GetFootNoteText(footNoteIndex As Integer) As String
Dim para_index As Integer
Dim temp_range As Variant
Dim footnote_text As String
footnote_text = ""
For para_index = 1 To m_word.ActiveDocument.Footnotes(footNoteIndex). _
Range.Paragraphs.Count
Set temp_range = m_word.ActiveDocument.Footnotes(footNoteIndex).Range. _
Paragraphs(para_index).Range
If para_index = 1 Then
temp_range.SetRange temp_range.start + 1, temp_range.End - 1
Else
temp_range.SetRange temp_range.start, temp_range.End - 1
End If
footnote_text = footnote_text + temp_range.Text & Chr(10) & Chr(13)
Next
GetFootNoteText = footnote_text
End Function
Private Sub DeleteFootNotes()
Dim footnote_index As Integer
Dim footnote_count As Integer
footnote_count = m_word.ActiveDocument.Footnotes.Count
For footnote_index = 1 To footnote_count
m_word.ActiveDocument.Footnotes(1).Delete
Next
End Sub
Private Sub InsertEndNotes(notesText As String)
Dim end_notes As Variant
Set end_notes = m_word.ActiveDocument.Range(,)
Call end_notes.InsertAfter("********" & Chr(10) & Chr(13) & notesText)
End Sub
Public Sub SetFont(font As String)
Call m_word.Selection.WholeStory
m_word.Selection.Font.Name = font
End Sub
Public Sub DeleteHeadersAndFooters()
Dim i As Integer
For i = 1 To m_word.ActiveDocument.Sections.Count
Call DeleteHeaderOrFooter(m_word.ActiveDocument.Sections(i).Headers(wdHeaderFooterFirstPage))
Call DeleteHeaderOrFooter(m_word.ActiveDocument.Sections(i).Headers(wdHeaderFooterEvenPages))
Call DeleteHeaderOrFooter(m_word.ActiveDocument.Sections(i).Headers(wdHeaderFooterPrimary))
Call DeleteHeaderOrFooter(m_word.ActiveDocument.Sections(i).Footers(wdHeaderFooterFirstPage))
Call DeleteHeaderOrFooter(m_word.ActiveDocument.Sections(i).Footers(wdHeaderFooterEvenPages))
Call DeleteHeaderOrFooter(m_word.ActiveDocument.Sections(i).Footers(wdHeaderFooterPrimary))
Next
End Sub
Private Sub DeleteHeaderOrFooter(headerOrFooter As Variant)
If (headerOrFooter.Exists) Then
headerOrFooter.LinkToPrevious = False
headerOrFooter.Range.Delete
End If
End Sub
Public Sub SetLeftMargin(centimeters As Double)
m_word.ActiveDocument.PageSetup.LeftMargin = m_word.CentimetersToPoints(centimeters)
End Sub
Public Sub Replace(oldText As String, newText As String)
m_word.Selection.Find.ClearFormatting
m_word.Selection.Find.Replacement.ClearFormatting
m_word.Selection.Find.Text = oldText
m_word.Selection.Find.Replacement.Text = newText
m_word.Selection.Find.Forward = True
m_word.Selection.Find.Wrap = wdFindContinue
Call m_word.Selection.Find.execute(,,,,,,,,,,wdReplaceAll)
End Sub
Public Sub ConvertQuotes
m_word.Options.AutoFormatAsYouTypeReplaceQuotes = False
Call Replace(Uchr(8220), """")
Call Replace(Uchr(8221), """")
End Sub
End Class