VB 6.0 - exporting from visual studio 6.0 to word document

Asked By uwabis okoh on 11-Nov-11 12:42 PM
please, i am having trouble exporting data from my grid and textboxes in visual studio to microsoft word document. i have been able to open an existing word document from visual studio, but i'm having trouble trasfering the data from my form to the word document. please can any body help me?
Kirtan Patel replied to uwabis okoh on 11-Nov-11 12:48 PM
here is code about how to write word document from vb.net

Public Shared Sub Main()
  Dim objWordApp As Word.Application
  objWordApp = New Word.Application
  Dim objDoc As New Word.Document
  'Show the Word application window if checked.
  objWordApp.Visible = IIf(chkShowWord.Checked, True, False)
  'Create a new Word document and add some text to it.
  objDoc = objWordApp.Documents.Add
  With objDoc
    .Range.InsertAfter("Printing with Word")
    .Paragraphs.Item(1).Range.Font.Bold = True
    .Paragraphs.Item(1).Range.Font.Size = 14
    .Paragraphs.Item(2).Range.Font.Bold = False
    .Paragraphs.Item(2).Range.Font.Size = 12
    .Range.InsertAfter("This is the first line of the test printout")
    .Range.InsertAfter("and this is the second line of the test printout")
      'Print the Word document.
      .PrintOut(True, True)
    Catch exc As Exception
    End Try
  End With
  objWordApp = Nothing
End Sub
dipa ahuja replied to uwabis okoh on 11-Nov-11 12:55 PM
Try this:

Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgsHandles Me.Load
    Dim objWordApp As Object
    Dim objWordDoc As Object
    objWordApp = CreateObject("Word.Application")
    objWordDoc = objWordApp.documents.add()
    objWordDoc.tables.add(objWordDoc.range(0, 0), 11, 3)
    With objWordDoc.tables(1)
      .borders.InsideLineStyle = 1
      .borders.OutsideLineStyle = 1
      For i As Integer = 0 To 10
        .rows(i + 1).cells(1).range.text = Me.dgvData.Rows(i).Cells("id").Value
        .rows(i + 1).cells(2).range.text = Me.dgvData.Rows(i).Cells("name").Value
        .rows(i + 1).cells(3).range.text = Me.dgvData.Rows(i).Cells("gender").Value
    End With
    objWordApp.visible = True
    objWordApp = Nothing
  End Sub
End Class