?
Solved

Using word Object Library in VB

Posted on 2003-11-13
5
Medium Priority
?
208 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
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 252 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 248 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month16 days, 14 hours left to enroll

864 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