creating word document using vb6.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sharayu
    New Member
    • Apr 2007
    • 1

    creating word document using vb6.0

    Hi
    I am doing a small project in vb.I want to create a word document consisting values in table format.The values are to be taken from the excel files.This is to be done using VB.The word file format will be fixed.So please can anybody help me with the Word VB Excel connectivity as soon as possible.
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #2
    Originally posted by sharayu
    Hi
    I am doing a small project in vb.I want to create a word document consisting values in table format.The values are to be taken from the excel files.This is to be done using VB.The word file format will be fixed.So please can anybody help me with the Word VB Excel connectivity as soon as possible.
    This should get you started. --Sam
    Code:
    Option Explicit
    Private Sub Command1_Click()
    	' Use Project, References menu to add
    	' Microsoft Word & Excel Object Libraries
    	Const XL_DOC As String = "N:\Programming\Word\WordTable\InputData.xls"
    	Const WD_DOC As String = "N:\Programming\Word\WordTable\ReadMe.doc"
    	Dim xlApp As New Excel.Application
    	Dim xlBook As Excel.Workbook
    	Dim wdApp As New Word.Application
    	Dim wdDoc As Word.Document
    	Dim wdTable As Word.Table
     
    	Set xlBook = xlApp.Workbooks.Open(FileName:=XL_DOC, ReadOnly:=True)
    	xlApp.Visible = True
    	Set wdDoc = wdApp.Documents.Add
    	wdApp.Visible = True
    	Set wdTable = wdDoc.Tables.Add(Range:=wdApp.Selection.Range, _
    		NumRows:=2, NumColumns:=4, DefaultTableBehavior:=wdWord9TableBehavior, _
    		AutoFitBehavior:=wdAutoFitFixed)
    	With xlBook.Worksheets("Sheet1")
    		wdTable.Cell(1, 1).Range.Text = .Cells(1, 1).Text
    		wdTable.Cell(1, 2).Range.Text = .Cells(1, 2).Text
    	End With
    	'xlApp.Quit
    	wdDoc.SaveAs FileName:=WD_DOC
    	'wdDoc.Quit
    End Sub

    Comment

    Working...