how do i fill out a table in a word document using VB6?

vb6 Sweden
  • 12 years ago

     i have a command button on my form and 6 textboxes as well (text1,text2,...,text6) and also there is a word document called mike.doc  at C:\mike.doc. this word document has only one empty 2x3 table in.

     

    what i want to do is:

     

    cell[1][1]= text1.text

    cell[1][2]= text2.text    .............................

     

    whats the code to do that?

    i have searched everywhere, nobody has helped so far with this, nobody knows.

    thanks in advance.
     

  • 12 years ago

    Add a reference to Microsoft Word

    Try
    Private Sub Form_Load()
        Dim sFile As String
        Dim objWord As Word.Application
        Dim objDocContent As Word.Range
       
        sFile = "C:\Mike.doc"
       
        Set objWord = New Word.Application
       
        ' Open the Document
        objWord.Documents.Open sFile

        ' Get the contents
        Set objDocContent = objWord.ActiveDocument.Content
            

       ActiveDocument.Tables.Item(1).Cell(1, 1).Range.Text = Text1.text
      
        ' Close the Document
        objWord.Documents.Close

          
        ' Quit Word
        objWord.Quit
        ' Destroy the object
        Set objWord = Nothing
       
    End Sub

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”