Solved

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

Posted on 2013-10-22
7
461 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

770 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