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
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