Solved

Using word Object Library in VB

Posted on 2003-11-13
5
193 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

14 Experts available now in Live!

Get 1:1 Help Now