I'm doing a project in VB. I have some textboxes in my VB user interface. Whenever the user enter value in those boxes and submit, i wan't to generate a Microsoft Word document with the values entered, incorporated with a template previously defined.
A standard template for the word is present. Only some fields in the template needs to be changed every time. These values will be supplied by the user through the interface. Finally when all the changes are made, the word document should be made with all those values.
The following code sample demonstrates how to open existing word template, insert a 3 x 5 table and fill it with specific data, finally save it. You need to Add Reference COM component: Microsoft Word Object Library to your project.
Imports Word = Microsoft.Office.Interop.Word
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Create Word Application
Dim oWord As Word.Application = CreateObject("Word.Application")
' Open existing word template
Dim oDoc As Word.Document = oWord.Documents.Open("C:\template.dot")
Dim oTable As Word.Table
oWord.Visible = True
'Insert a 3 x 5 table and fill it with specific data