Solved

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

Posted on 2013-10-22
7
472 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 32

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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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.

734 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