PDA

View Full Version : VBA Coding commands



newk
05-26-2005, 01:41 AM
Hello, I have a template that on opening brings up a dialog box giving options.
Depending on the option selected the macro outputs the required footer.
The problem is that I only want the footer to be output on the front page. At the moment the code is going to the current page (2 maybe 3) and outputting, to all sheets except the front sheet.
I am currently using this code:
Select Case True

Case Is = Me.optBrighton
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.MoveDown Unit:=wdLine, Count:=9
Selection.Range.Text = "67 Old kent Road DX1111 London 1 Registered in England No 11111"
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
With Selection
.Font.Size = 8
.Paragraphs.Alignment = wdAlignParagraphLeft
End With
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeParagraph
Selection.Range.Text = "Tel: 0161 585265 Fax:0161 555555 Email: info@test.co.uk Registered Office: Old kent road, London, UK"
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
With Selection
.Font.Size = 8
.Paragraphs.Alignment = wdAlignParagraphLeft
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

Case Is = Me.OptManchester
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.MoveDown Unit:=wdLine, Count:=9
Selection.Range.Text = "Picadilly, London L56 8RF Registered in England No 22222"
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
With Selection
.Font.Size = 8
.Paragraphs.Alignment = wdAlignParagraphLeft
End With
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeParagraph
Selection.Range.Text = "Tel: 0161 855559 Fax:0178 3333333 Email: info@test.co.uk Registered Office: old kent road, London, UK"
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
With Selection
.Font.Size = 8
.Paragraphs.Alignment = wdAlignParagraphLeft
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument


End Select

PLEASE HELP!:hi:

Tommy
05-26-2005, 06:47 AM
Hi newk,
Try this instead of using seek current page footer use seek first page footer.

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageFooter

HTH
Tommy

newk
05-26-2005, 07:00 AM
Thanks Tommy thats great! :thumb

fumei
05-26-2005, 07:16 AM
Assuming you only want the footer on the first page - and be careful if you are using other Sections - you can explicitly set the text without going into Views.

Select Case True
Case Is = Me.optBrighton
With Selection
With .PageSetup
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
End With
With .Sections(1).Footers
.Item(1).Range.Text = "67 Old kent Road DX1111 " & _
London 1 Registered in England No 11111"
.Item(2) = ""
.Item(3) = ""
End With
etc etc etc

MOS MASTER
05-26-2005, 09:48 AM
Thanks Tommy thats great! :thumb

Hi and Welcome to VBAX! :hi:

Glad to see your problem is fixed!
Would you be so kind to mark your thread solved?

To improve your code try Fumei's suggestion. That is more reliable, faster and error resistent then going into views which is also slower.

:whistle: