Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Inserting text into a word document using a macro

Posted on 2015-01-22
2
Medium Priority
?
92 Views
Last Modified: 2015-01-23
I am trying to write a macro to insert a word at the beginning of each paragraph based on a selection in a Microsoft Word document.  For example, "1. Some text here" would change to "WORD 1. Some text here" after running the macro.  So far I have this, but I only want the Macro to run with a selection, not the whole document.

Sub addNotes()

    iParCount = ActiveDocument.Paragraphs.Count
    For j = 1 To iParCount
        sMyPar = "Note " + ActiveDocument.Paragraphs(j).Range.Text
        ActiveDocument.Paragraphs(j).Range.Text = sMyPar
    Next j

End Sub

Thanks.
0
Comment
Question by:rcimasi
[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
2 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 40565893
Hi,

pls try

Sub addNotes()
    Set myRange = Selection.Range

    For Idx = 1 To myRange.Paragraphs.Count
        myRange.Paragraphs(Idx).Range.Text = "Note " + myRange.Paragraphs(Idx).Range.Text
    Next

End Sub

Open in new window

Regards
0
 

Author Comment

by:rcimasi
ID: 40566506
That worked like a charm, thanks.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

704 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