[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Using word Object Library in VB

Posted on 2003-11-13
Medium Priority
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?
Question by:Dhanish
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
LVL 53

Accepted Solution

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
    .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

Assisted Solution

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.
LVL 49

Expert Comment

ID: 10548299
Moderator, my recommended disposition is:

    Split points between: Dhaest & atp_expert

Dan Rollins -- EE database cleanup volunteer

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

649 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