Solved

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

Posted on 2013-10-22
7
459 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
Comment Utility
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
Comment Utility
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é
Comment Utility
>> 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:nonlinearly
Comment Utility
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
Comment Utility
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
Comment Utility
GrahamSkan,
If I want pages and not sections?
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
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.

762 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

6 Experts available now in Live!

Get 1:1 Help Now