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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert text into first page header only. 1

Status
Not open for further replies.

JohnnyLong

Programmer
Sep 27, 2002
97
GB
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
 
Ok, the header is just our company logo .jpg and the header is text, address, phone numbers etc.
The table on the first page is a summary table, 10 rows by 2 columns:
Applicant Joe Bloggs
Contact 020 8777333
Nationality British
Resides London
Willing to locate Yes
Willing to travel Yes
Current Position Programmer
Required Position Analyst
Current Salary £40000
Required Salary £50000

The cv should then show on the following pages in the format the candidate sent.

John
 
The first column is pre-filled and the second column is entered by the user. The user opens the cv, clicks the format button, types the candidates details in the second column, checks the formatting of the cv text and saves the document.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top