JohnnyLong
Programmer
I have a Word 2000 macro that inserts text and logos into the header and footer of word docs. How do I change it so the text is only inserted into the first page header?
Here is the code:
Sub FormatCVTemplate()
Dim tmpFileName
Dim Template
Dim OriginalFileName
Dim OriginalPath
Dim FontSize
Dim FontName
Const ROOT_DRIVE = "C:\"
OriginalFileName = ActiveDocument.Name
OriginalPath = ActiveDocument.Path
tmpFileName = ROOT_DRIVE & "Macro\tmpDoc.doc"
' Save CV document
ActiveDocument.SaveAs (tmpFileName)
' Open Template Document
Documents.Open FileName:=ROOT_DRIVE & "Macro\FormatCVTemplate.doc"
Template = ActiveDocument.Name
If Documents(Template).ActiveWindow.View.SplitSpecial <> wdPaneNone Then
Documents(Template).ActiveWindow.Panes(2).Close
End If
If Documents(Template).ActiveWindow.ActivePane.View.Type = wdNormalView Or _
Documents(Template).ActiveWindow.ActivePane.View.Type = wdOutlineView Then
Documents(Template).ActiveWindow.ActivePane.View.Type = wdPrintView
End If
' Copy header from template
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
FontSize = Selection.Font.Size
FontName = Selection.Font.Name
Selection.Copy
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
' Open tmpFileName document
Documents(tmpFileName).Activate
If Documents(tmpFileName).ActiveWindow.View.SplitSpecial <> wdPaneNone Then
Documents(tmpFileName).ActiveWindow.Panes(2).Close
End If
If Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdNormalView Or _
Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdOutlineView Then
Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdPrintView
End If
' Paste template header into tmpFileName
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.Paste
Selection.TypeBackspace
Selection.WholeStory
Selection.Font.Size = FontSize
Selection.Font.Name = FontName
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
' Open template document
Documents(Template).Activate
If Documents(Template).ActiveWindow.View.SplitSpecial <> wdPaneNone Then
Documents(Template).ActiveWindow.Panes(2).Close
End If
If Documents(Template).ActiveWindow.ActivePane.View.Type = wdNormalView Or _
Documents(Template).ActiveWindow.ActivePane.View.Type = wdOutlineView Then
Documents(Template).ActivePane.View.Type = wdPrintView
End If
' Copy footer from template
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.WholeStory
Selection.Copy
FontSize = Selection.Font.Size
FontName = Selection.Font.Name
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
' Paste template footer into formatted tmpFileName
Documents(tmpFileName).Activate
If Documents(tmpFileName).ActiveWindow.View.SplitSpecial <> wdPaneNone Then
Documents(tmpFileName).ActiveWindow.Panes(2).Close
End If
If Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdNormalView Or _
Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdOutlineView Then
Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdPrintView
End If
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.Paste
Selection.TypeBackspace
Selection.WholeStory
Selection.Font.Size = FontSize
Selection.Font.Name = FontName
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
' Open template document
Documents(Template).Activate
' Copy any text from the template
Selection.WholeStory
Selection.Copy
' Close template
Documents(Template).Close
' Paste text from template into tmpFileName
Selection.Paste
' Save formatted CV using original filename
ActiveDocument.SaveAs (OriginalPath + "\" + OriginalFileName)
' Delete tmpFileName file
Set fs = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
fs.DeleteFile (tmpFileName)
End Sub
Thanks in advance,
John
Here is the code:
Sub FormatCVTemplate()
Dim tmpFileName
Dim Template
Dim OriginalFileName
Dim OriginalPath
Dim FontSize
Dim FontName
Const ROOT_DRIVE = "C:\"
OriginalFileName = ActiveDocument.Name
OriginalPath = ActiveDocument.Path
tmpFileName = ROOT_DRIVE & "Macro\tmpDoc.doc"
' Save CV document
ActiveDocument.SaveAs (tmpFileName)
' Open Template Document
Documents.Open FileName:=ROOT_DRIVE & "Macro\FormatCVTemplate.doc"
Template = ActiveDocument.Name
If Documents(Template).ActiveWindow.View.SplitSpecial <> wdPaneNone Then
Documents(Template).ActiveWindow.Panes(2).Close
End If
If Documents(Template).ActiveWindow.ActivePane.View.Type = wdNormalView Or _
Documents(Template).ActiveWindow.ActivePane.View.Type = wdOutlineView Then
Documents(Template).ActiveWindow.ActivePane.View.Type = wdPrintView
End If
' Copy header from template
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
FontSize = Selection.Font.Size
FontName = Selection.Font.Name
Selection.Copy
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
' Open tmpFileName document
Documents(tmpFileName).Activate
If Documents(tmpFileName).ActiveWindow.View.SplitSpecial <> wdPaneNone Then
Documents(tmpFileName).ActiveWindow.Panes(2).Close
End If
If Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdNormalView Or _
Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdOutlineView Then
Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdPrintView
End If
' Paste template header into tmpFileName
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.Paste
Selection.TypeBackspace
Selection.WholeStory
Selection.Font.Size = FontSize
Selection.Font.Name = FontName
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
' Open template document
Documents(Template).Activate
If Documents(Template).ActiveWindow.View.SplitSpecial <> wdPaneNone Then
Documents(Template).ActiveWindow.Panes(2).Close
End If
If Documents(Template).ActiveWindow.ActivePane.View.Type = wdNormalView Or _
Documents(Template).ActiveWindow.ActivePane.View.Type = wdOutlineView Then
Documents(Template).ActivePane.View.Type = wdPrintView
End If
' Copy footer from template
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.WholeStory
Selection.Copy
FontSize = Selection.Font.Size
FontName = Selection.Font.Name
Documents(Template).ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
' Paste template footer into formatted tmpFileName
Documents(tmpFileName).Activate
If Documents(tmpFileName).ActiveWindow.View.SplitSpecial <> wdPaneNone Then
Documents(tmpFileName).ActiveWindow.Panes(2).Close
End If
If Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdNormalView Or _
Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdOutlineView Then
Documents(tmpFileName).ActiveWindow.ActivePane.View.Type = wdPrintView
End If
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.Paste
Selection.TypeBackspace
Selection.WholeStory
Selection.Font.Size = FontSize
Selection.Font.Name = FontName
Documents(tmpFileName).ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
' Open template document
Documents(Template).Activate
' Copy any text from the template
Selection.WholeStory
Selection.Copy
' Close template
Documents(Template).Close
' Paste text from template into tmpFileName
Selection.Paste
' Save formatted CV using original filename
ActiveDocument.SaveAs (OriginalPath + "\" + OriginalFileName)
' Delete tmpFileName file
Set fs = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
fs.DeleteFile (tmpFileName)
End Sub
Thanks in advance,
John