Word Help! Word 2007 Macro Recording

Joined
Mar 13, 2009
Messages
1
Reaction score
0
Hi,

I'm trying to create a macro in Word 2007 to input the file name/path and the page number, both of which should be centred and in arial font sized 9.

So far I am about 2/3 of the way there but keep getting stuck as it keeps telling me "Run-time error 5941 the requested member of the collection does not exist".

I have managed to create the following macro which will input the file name/path and page number but does not centre it or format the text how I wish:-

Sub Footer()
'
' Footer Macro
'
'
WordBasic.ViewFooterOnly
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME \p ", PreserveFormatting:=True
Selection.TypeParagraph
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PAGE \* Arabic ", PreserveFormatting:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
Sub Textstyle()
'
' Textstyle Macro
'
'
Selection.WholeStory
Selection.Font.Name = "Arial"
Selection.Font.Size = 11
With Selection.ParagraphFormat
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 6
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
End With
End Sub
Sub Macro1()
'
' Macro1 Macro
'
'
WordBasic.ViewFooterOnly
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Size = 9
WordBasic.ViewFooterOnly
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Plain Number 2"). _
Insert Where:=Selection.Range, RichText:=True
Selection.TypeParagraph
Selection.TypeParagraph
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME \p ", PreserveFormatting:=True
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Size = 9
End Sub
Sub FooterMacro()
'
' FooterMacro Macro
'
'
WordBasic.ViewFooterOnly
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME \p ", PreserveFormatting:=True
Selection.TypeParagraph
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Plain Number"). _
Insert Where:=Selection.Range, RichText:=True
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Font.Name = "Arial"
Selection.Font.Size = 9
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
End Sub


When I tried to record another macro in order to format the text it gave me the aforementioned error code. This is the script for the macro showing this error message:-

Sub Footer()
'
' Footer Macro
'
'
WordBasic.ViewFooterOnly
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME \p ", PreserveFormatting:=True
Selection.TypeParagraph
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PAGE \* Arabic ", PreserveFormatting:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
Sub Textstyle()
'
' Textstyle Macro
'
'
Selection.WholeStory
Selection.Font.Name = "Arial"
Selection.Font.Size = 11
With Selection.ParagraphFormat
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 6
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
End With
End Sub
Sub Macro1()
'
' Macro1 Macro
'
'
WordBasic.ViewFooterOnly
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Size = 9
WordBasic.ViewFooterOnly
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Plain Number 2"). _
Insert Where:=Selection.Range, RichText:=True
Selection.TypeParagraph
Selection.TypeParagraph
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME \p ", PreserveFormatting:=True
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Size = 9
End Sub
Sub FooterMacro()
'
' FooterMacro Macro
'
'
WordBasic.ViewFooterOnly
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME \p ", PreserveFormatting:=True
Selection.TypeParagraph
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Plain Number"). _
Insert Where:=Selection.Range, RichText:=True
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Font.Name = "Arial"
Selection.Font.Size = 9
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
End Sub


Anyone got any ideas how I can either create a new macro or edit the existing one to take into account the formatting I want it to do?

Many thanks,

Daisy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top