Link to home
Start Free TrialLog in
Avatar of nonlinearly
nonlinearly

asked on

Word 2010 set specific text to 4rd line break in every page using VBA

Hi,
I have a word with 5.000 pages and every page is a different section... I need in 4rd line break (that already exist and has nothing) on each page to set a sequentially number... I think that I will not avoid VBA to do this but how?
Thanks
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

It it is a little difficult to be sure of what you are trying to do.

I assume that you need the fourth, currently empty, paragraph in each section of your document to contain a sequential number.

This should do that:
Sub InsertNumber()
    Dim sec As Section
    Dim para As Paragraph
    Dim i As Integer
    
    For Each sec In ActiveDocument.Sections
        i = i + 1
        sec.Range.Paragraphs(4).Range.Text = i & vbCr
    Next sec
End Sub

Open in new window

Can you clarify the "4rd line break" part? You may be able to do this if you have a pattern that can be used with a wildcard search within the Find dialog. For the sequential numbering, I would recommend using a SEQ field code -- and that could be put into the document using Replace if a Find pattern can be used.

Can you post a small representative sample of the document?
>> I need in 4rd line break (that already exist and has nothing) on each page to set a sequentially number...

Not nearly clear enough to help you answer your question!

Do you want to insert a new paragraph (^p) break or a new line (^l) on each page?

Do you want to insert it at a specific location on the page, or is the location not important?

What dou you mean by set a sequentially number? Does the number already exist? Is it a page number?
Avatar of nonlinearly
nonlinearly

ASKER

GrahamSkan,
it works.. but it looses the right adjustment-alignment that has and converted to left...
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
GrahamSkan,
If I want pages and not sections?
That is more difficult. The Page object does not return the range or its text, because what is on the page depends on the pagination which is done dynamically.
If there were manual page breaks, however, we could look for the fourth paragraph after each one.