![]() |
|
|
|
#1
|
|||
|
|||
|
Hi,
I need a VBA to make a line on the top of every page in a word document ( more than 250 pages ) . it can be done by writing 3 hyphens and click enter afterwards but it would take long to do it over the whole document. Any hep appreciated, thanks in advance. Younan |
|
#2
|
||||
|
||||
|
So why not do it once in the page header? No VBA required.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Hi,
Thanks for your reply, i am asking for VBA cause above this line i will write different text almost in every page, which as i think cant be done with header. bEst regards Younan |
|
#4
|
|||
|
|||
|
Then apply a style to the text that you will write at the top of each page that includes a bottom border.
If you insert the line using VBA at the top of each page and then add text before it the line on subsequent pages will not be at the top of the page any more. |
|
#5
|
|||
|
|||
|
Hi
I ll show a picture on how it appears in my file if i use hyphen to insert a line. The text in line with number one is what will change almost in every page. Any ideas ? |
|
#6
|
||||
|
||||
|
If the changing text is just the page number, then all you need to do is add a page field to the header along with your static text. Otherwise, you could use something like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim p As Long, Shp As Shape, sWdth As Single
With ActiveDocument
With .PageSetup
sWdth = .PageWidth - .LeftMargin - .RightMargin - .Gutter
End With
Do While p < .ComputeStatistics(wdStatisticPages)
p = p + 1
Set Shp = .Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, sWdth, 24, .GoTo(What:=wdGoToPage, Name:=p))
With Shp
.LockAnchor = True
.Line.Visible = False
.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
.Left = wdShapeCenter
.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
.Top = -18
With .TextFrame.TextRange.ParagraphFormat
.SpaceBefore = 0
.SpaceAfter = 0
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
End With
End With
Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#7
|
|||
|
|||
|
Quote:
Look into the StyleRef Field. That lets you have a single header that has different text on every page depending on the content of the page. You can have a bottom border for the paragraph. This would best be done as a modification of the Header style. By the way, when you type the thee hyphens --- and press Enter, what you get is a bottom paragraph border created by AutoFormat As You Type. See also Word Doesn't Know What a Page Is by Daiya Mitchell, MVP( https://wordmvp.com/Mac/PagesInWord.html). |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 1st line of 4-line poem centrally aligned; how to get lines 2-4 to start at same location on page | Swarup | Word | 6 | 09-16-2022 11:07 AM |
Making mail merge blank fill a line to highlight that line
|
rgm60527 | Mail Merge | 2 | 02-22-2022 11:13 AM |
word erases line bottom in tight line spacing when new line is added
|
ozzzy | Word | 2 | 01-21-2021 06:41 AM |
| Usability of space between final line of body text and footnote separator line | Swarup | Word | 6 | 07-28-2018 12:51 PM |
MS Word Horizontal Line Disappears after pressing Enter from end of line
|
MikeWhite | Word | 5 | 01-20-2017 03:39 PM |