Solved

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

Posted on 2013-10-22
7
460 Views
Last Modified: 2013-10-23
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
0
Comment
Question by:nonlinearly
7 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39592807
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

0
 
LVL 21

Expert Comment

by:EricFletcher
ID: 39592813
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?
0
 
LVL 31

Expert Comment

by:Paul Sauvé
ID: 39592821
>> 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?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:nonlinearly
ID: 39593468
GrahamSkan,
it works.. but it looses the right adjustment-alignment that has and converted to left...
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39593529
I don't know why it gets lost, but this macro will apply the right alignment again.
Sub InsertNumber()
    Dim sec As Section
    Dim para As Paragraph
    Dim i As Integer

    For Each sec In ActiveDocument.Sections
        i = i + 1
        Set para = sec.Range.Paragraphs(4)
        para.Range.Text = i & vbCr
        para.Alignment = wdAlignParagraphRight
    Next sec
End Sub

Open in new window

If it doesn't work, can you reword your problem and provide a sample first page, please
0
 

Author Comment

by:nonlinearly
ID: 39593582
GrahamSkan,
If I want pages and not sections?
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39593611
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now