Solved

How programmatically insert text into word document?

Posted on 2004-10-13
7
984 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
A Knowledge Base That Stays Up-to-Date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now