Solved

Using word Object Library in VB

Posted on 2003-11-13
5
203 Views
Last Modified: 2010-05-03
I have write some text in Word docuemnt using range object. After this I had added a table in to that docuement.  And again inserted some text. But the table is reside at end of docuemnt. why?
How I can insert a table in a Word document?
0
Comment
Question by:Dhanish
[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
5 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 63 total points
ID: 9745912
Dim wdApp As New Word.Application
Dim wdDoc As New Word.Document
Dim wdTable As Word.Table
Dim saveas As String

wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add

With wdApp.Selection
    .ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
    .TypeText ("TIME OFF REQUEST FORM")
    .ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft

    Set wdTable = wdDoc.Tables.Add(Range:=.Range, NumRows:=2, NumColumns:=4)


' change the layout of the table
    with wdTable
                .Borders.Enable = True
                .Cell(1, 1).Range.Font.Bold = True
                .Cell(1, 1).Width = wdApp.InchesToPoints(0.75)
                .Cell(1, 1).Range.Text = "Date:"
                .Cell(1, 2).Range.Font.Bold = False
                .Cell(1, 2).Width = wdApp.InchesToPoints(2)
                .Cell(1, 2).Range.Text = date1.Text
                .Cell(1, 3).Range.Font.Bold = True
                .Cell(1, 3).Width = wdApp.InchesToPoints(0.75)
                .Cell(1, 3).Range.Text = "Name:"
                .Cell(1, 4).Range.Font.Bold = False
                .Cell(1, 4).Width = wdApp.InchesToPoints(2)
                .Cell(1, 4).Range.Text = Name1.Text
                .Cell(2, 1).Range.Font.Bold = True
                .Cell(2, 1).Width = wdApp.InchesToPoints(0.75)
                .Cell(2, 1).Range.Text = "Dept:"
                .Cell(2, 2).Range.Font.Bold = False
                .Cell(2, 2).Width = wdApp.InchesToPoints(2)
                .Cell(2, 2).Range.Text = TextBox3.Text
                .Cell(2, 3).Width = wdApp.InchesToPoints(0.75)
                .Cell(2, 3).Range.Font.Bold = True
                .Cell(2, 3).Range.Text = "Location:"
                .Cell(2, 4).Range.Font.Bold = False
                .Cell(2, 4).Width = wdApp.InchesToPoints(2)
                .Cell(2, 4).Range.Text = TextBox5.Text
          ...
end with
0
 
LVL 1

Assisted Solution

by:atp_expert
atp_expert earned 62 total points
ID: 9747498
The reason of this is that, when the table is drawn, the cursor resides at the first cell of the table. What u need to do is.. get the cursor end of that table and get the cursor to the next line to the table and start writing. By this way ur table will remain at the proper position.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 10548299
Moderator, my recommended disposition is:

    Split points between: Dhaest & atp_expert

Dan Rollins -- EE database cleanup volunteer
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

688 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