Solved

How programmatically insert text into word document?

Posted on 2004-10-13
7
989 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF to Word 25 155
Word 2016 stuck on "starting" splash screen 10 1,394
Convert .PDF 6 65
how can I correct in impaired MS Word 2013 invoice template print out? 8 61
If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
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 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.
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 …

776 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