# [SOLVED] Macro Problem - Word 2003



## leza (Dec 17, 2007)

Hello everyone,
I could sure use some help with the following macro! Every time I think I have things worked out it seems to "Blow up" on me. 

The macro is designed to put "letterhead" on any document. A new blank document or a letter with existing text. 

The "letterhead" consists of the person's personal information, stored in a "mynames.doc", and the attorney's names, stored in the "attorneysnames.doc” file. They are copied from a separate file, so if the names change they can be modified in one place. I pasted the text in frames on the first page and defined the dimensions and formatted the frame border to be clear. 
The margins for the first page need to be different from the margins of the rest of the pages, although sometimes there is one page and other times there are more. I addressed this by putting a transparent frame below the others to force the text to wrap around it. 
Although I have had glitches come up in all of the above steps, they are working right now. 
The problem right now is at the very end, where it inserts the date. I need it to come down 3 lines from the top, insert the date code, and come down 2 more lines. It is working in a blank document but not when the document has text in it already. It is putting the date at the bottom, instead of the top. I know there has to be an easy fix. Someway of saying goto the top of main document (NOT frame 1, 2 or3) 
Thanks for reading this lengthy entry!!! I appreciate any help you can give me!!!!

HERE IS THE WHOLE MACRO:

Sub letterhead()
'
' letterhead Macro
' Macro recorded 12/13/2007 by Leza Wood
'
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.25)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterUpperBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
 .SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
ActiveDocument.Frames.Add Range:=Selection.Range
With Selection.Frames(1)
.Select
.TextWrap = True
.WidthRule = wdFrameExact
.Width = InchesToPoints(1.24)
.HeightRule = wdFrameExact
.Height = InchesToPoints(1)
.HorizontalPosition = InchesToPoints(0.4)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.VerticalPosition = InchesToPoints(1)
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.HorizontalDistanceFromText = InchesToPoints(0.13)
.VerticalDistanceFromText = InchesToPoints(0)
.LockAnchor = True
End With
ActiveWindow.ActivePane.HorizontalPercentScrolled = 0
ChangeFileOpenDirectory "C:\Documents and Settings\"
Documents.Open FileName:="""my name.doc""", ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
ActiveDocument.Shapes("Text Box 2").Select
Selection.WholeStory
Selection.Copy
ActiveDocument.Save
ActiveDocument.Close
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.Frames.Add Range:=Selection.Range
With Selection.Frames(1)
.Select
.TextWrap = True
.WidthRule = wdFrameExact
.Width = InchesToPoints(1.24)
.HeightRule = wdFrameExact
.Height = InchesToPoints(5)
.HorizontalPosition = InchesToPoints(0.4)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.VerticalPosition = InchesToPoints(1.75)
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.HorizontalDistanceFromText = InchesToPoints(0.13)
.VerticalDistanceFromText = InchesToPoints(0)
.LockAnchor = True
End With
Documents.Open FileName:="""attorney names.doc""", ConfirmConversions:= _
False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
ActiveDocument.Shapes("Text Box 2").Select
Selection.WholeStory
Selection.Copy
ActiveDocument.Save
ActiveDocument.Close
Selection.PasteAndFormat (wdPasteDefault)
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
CommandBars("Task Pane").Visible = False
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(-0.58)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
With Selection.ParagraphFormat
.RightIndent = InchesToPoints(-0.58)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Name = "Rotis Serif Std"
Selection.Font.Size = 10
Selection.TypeText Text:="Street Name "
Selection.InsertSymbol Font:="Wingdings", CharacterNumber:=-3937, Unicode _
:=True
Selection.TypeText Text:=" P.O. Box Here"
Selection.InsertSymbol Font:="Wingdings", CharacterNumber:=-3937, Unicode _
:=True
Selection.TypeText Text:=" AnyCity, ST 00000 "
Selection.InsertSymbol Font:="Wingdings", CharacterNumber:=-3937, Unicode _
:=True
Selection.TypeText Text:=" Phone: (000)000-0000 "
Selection.InsertSymbol Font:="Wingdings", CharacterNumber:=-3937, Unicode _
:=True
Selection.TypeText Text:=" Fax: (000)000-0000 "
Selection.TypeParagraph
Selection.TypeText Text:="Street Address "
Selection.InsertSymbol Font:="Wingdings", CharacterNumber:=-3937, Unicode _
:=True
Selection.TypeText Text:=" AnyCity, ST 00000 "
Selection.InsertSymbol Font:="Wingdings", CharacterNumber:=-3937, Unicode _
:=True
Selection.TypeText Text:=" Phone: (000)000-0000 "
Selection.InsertSymbol Font:="Wingdings", CharacterNumber:=-3937, Unicode _
:=True
Selection.TypeText Text:=" Fax: (000)000-0000 "
Selection.TypeParagraph
Selection.TypeText Text:="www.websiteaddress.com"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.WholeStory
Selection.MoveLeft Unit:=wdCharacter, Count:=1
With Selection.Frames(1)
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
Selection.MoveDown Unit:=wdLine, Count:=7
With Selection.ParagraphFormat
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
With .Borders
.DistanceFromTop = 1
.DistanceFromLeft = 4
.DistanceFromBottom = 1
.DistanceFromRight = 4
.Shadow = False
End With
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth075pt
.DefaultBorderColor = wdColorAutomatic
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdStory
Selection.MoveUp Unit:=wdLine, Count:=4
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.MoveUp Unit:=wdLine, Count:=4
Selection.MoveDown Unit:=wdLine, Count:=5
Selection.MoveLeft Unit:=wdCharacter, Count:=21
With Selection.ParagraphFormat
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
With .Borders
.DistanceFromTop = 1
.DistanceFromLeft = 4
.DistanceFromBottom = 1
.DistanceFromRight = 4
.Shadow = False
End With
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth075pt
.DefaultBorderColor = wdColorAutomatic
End With
Selection.MoveUp Unit:=wdLine, Count:=28
Selection.MoveRight Unit:=wdCharacter, Count:=29
Selection.MoveDown Unit:=wdLine, Count:=31
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.InsertDateTime DateTimeFormat:="MMMM d, yyyy", InsertAsField:= _
True, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
Selection.TypeParagraph
Selection.TypeParagraph
ActiveDocument.Frames.Add Range:=Selection.Range
With Selection.Frames(1)
.Select
.TextWrap = True
.WidthRule = wdFrameExact
.Width = InchesToPoints(1.24)
.HeightRule = wdFrameAtLeast
.Height = InchesToPoints(3)
.HorizontalPosition = InchesToPoints(0.4)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.VerticalPosition = InchesToPoints(6.75)
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.HorizontalDistanceFromText = InchesToPoints(0.13)
.VerticalDistanceFromText = InchesToPoints(0)
.LockAnchor = True
End With
ActiveWindow.ActivePane.VerticalPercentScrolled = 28
With Selection.Frames(1)
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth075pt
.DefaultBorderColor = wdColorAutomatic
End With
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
ActiveWindow.ActivePane.VerticalPercentScrolled = 55
Selection.MoveUp Unit:=wdLine, Count:=31
Selection.MoveRight Unit:=wdCharacter, Count:=56
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.MoveRight Unit:=wdCharacter, Count:=28
Selection.MoveDown Unit:=wdLine, Count:=10
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=3
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=2
ActiveWindow.ActivePane.SmallScroll Down:=-12
End Sub


----------



## leza (Dec 17, 2007)

*Re: Macro Problem - Word 2003*

I tried to Insert a bookmark at the top and then goto bookmark at the end. It didn't work - Said bookmark doesn't exist?!


----------

