You are on page 1of 1

Imports Word = Microsoft.Office.Interop.

Word
Public Class Form2
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")
' Create new word document
Dim oDoc As Word.Document = oWord.Documents.Add()
oWord.Visible = True
'Insert a 3 x 5 table and fill it with specific data
Dim r As Integer, c As Integer
Dim oTable As Word.Table =
oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, 3, 5)
oTable.Range.ParagraphFormat.SpaceAfter = 6
For r = 1 To 3
For c = 1 To 5
oTable.Cell(r, c).Range.Text = "Row" & r & "Col" & c
Next
Next
'make the first row bold and italic
oTable.Rows.Item(1).Range.Font.Bold = True
oTable.Rows.Item(1).Range.Font.Italic = True
' Save this word document
oDoc.SaveAs("C:\Users\ADMIN\Desktop\myfile.doc", True)
oDoc.Close()
oWord.Application.Quit()
End Sub
End Class

You might also like