PDA

View Full Version : Header and Footer Trouble



figment
10-26-2007, 11:44 AM
I am trying to write a macro that:

opens a document
formats the text
sets the first page header and footer to be different
puts a picture into the first page header
puts a picture into the first page footer
saves the document under a new name.

I managed to get almost all of it from recording macros, and previous experience. But I can’t figure out how to put the pictures into there perspective locations. The record macro has it using the select move commands, but they have been proven to be unreliable in the past, and i would rather not have to use them, for I don’t know if there is already text in the header and/or footer.

here is what i have so far


Sub PROPOSALS()
Dim doc As Word.Document
Dim fd As FileDialog
Dim path As String
Dim canceling As Boolean
canceling = True
Set fd = Word.Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.Filters.Add "All Files", "*.*", 1
.Show
If .SelectedItems.Count > 0 Then path = .SelectedItems(1) Else canceling = False
End With
If canceling Then

Set doc = Word.Documents.Open(path)


With Selection.ParagraphFormat
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
.Alignment = wdAlignParagraphJustify
End With

ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

Selection.InlineShapes.AddPicture FileName:= _
"C:\Documents and Settings\brs\My Documents\My Pictures\0211 cop2 copy.jpg" _
, LinkToFile:=False, SaveWithDocument:=True
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.InlineShapes.AddPicture FileName:= _
"C:\Documents and Settings\brs\My Documents\My Pictures\BRAINP 1 cop2 copy.jpg" _
, LinkToFile:=False, SaveWithDocument:=True
Set fd = Word.Application.FileDialog(msoFileDialogSaveAs)
While canceling
With fd
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
path = .SelectedItems(1)
canceling = False
Else
canceling = True
End If
End With
Wend
ActiveDocument.SaveAs (path)
End If
End Sub

I apologize if this question has already been addressed else where.

Any help would be appreciated

lucas
10-26-2007, 12:07 PM
I don't understand why you don't just use a template? Can you explain?

figment
10-26-2007, 10:18 PM
the file with the text is created by a program other then word.

lucas
10-27-2007, 08:20 AM
Hi figment,
It still seems practical to set up a template and bring the text to it....is there a reason that would not work?

figment
10-29-2007, 04:46 AM
seems i need to learn more of the ways of word. the template works great thanks for the idea.

fumei
10-29-2007, 08:17 AM
1. A template would be best, as that is what they are for.

2. "formats the text"....use Styles!

3. you can make headers and footers be whatrever you weant directly, using header/footer objects.

4. You want to consider making your images AutoText, and using that to put them into your headers/footers.

But again, if this was a template, then all that stuff would already BE there.