Solved

How programmatically insert text into word document?

Posted on 2004-10-13
7
995 Views
Last Modified: 2012-08-13
I need programmatically insert text into word document and it should be placed in particular location (say 30 points from top and 50 points from left). I can not consider TextBox, it must be "regular" string.
Is there any way to accomplish this?

TIA  
0
Comment
Question by:MTchary
[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
  • 4
  • 2
7 Comments
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 12304494
Are you gathering the information to be placed there from a VBA user form?  If so, you could do something like this:

    If frmPB.TextBox2.Text <> "" Then
        Selection.Bookmarks.Add Name:="address", Range:=Selection.Range
        Selection.Style = "Address"
        Selection.TypeText frmPB.TextBox3.Text
        Selection.TypeParagraph
    End If
    If frmPB.TextBox4.Text <> "" Then
        Selection.Style = "Salutation"
        Selection.TypeText frmPB.TextBox4.Text
    End If

0
 
LVL 11

Expert Comment

by:Steiner
ID: 12305451
Since Word is "paragraph oriented" it may be difficult to have words "floating" in your document without using a textfield.
Maybe you can layout the document and place bookmarks where you later want the text to go. So place a bookmark just 30 points from top and 50 points from left by inserting paragraphs, tabs and spaces.
Now you just need to use:

ActiveDocument.Bookmarks("YourBookmarkName").Range.Text = myString
0
 

Author Comment

by:MTchary
ID: 12307364
It seems to me that I can use only 'Paragraph' and 'Tab' to position Text in a Document at defined location. But, I think, it will be hard to place text in particular position because 'Paragraph' has constant height and 'Tab' has its constant length. Or may be exist a way to manage those value (height & length)?

TIA
0
Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 12310004
How about Insert, Field, Advance?
0
 
LVL 11

Accepted Solution

by:
Steiner earned 65 total points
ID: 12336443
Well, the height of an paragraph is determined by the font size and the space between paragraphs (Format - Paragraph). The tab width you can set by using the horzontal ruler or using then menu Format - Paragraph - Tab.
0
 
LVL 37

Assisted Solution

by:Joanne M. Orzech
Joanne M. Orzech earned 60 total points
ID: 12375537
Spacing between paragraphs can be changed by selecting the paragraph and go to Format, Paragraph, Line Spacing, and change it to something less....if you select "exactly" 8 pt. or something - as Steiner said - it depends on the size of your font.

Hope that helps
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 12380697
Thank you!  Glad it's working for you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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