Solved

How programmatically insert text into word document?

Posted on 2004-10-13
7
994 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
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 …

733 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