By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,828 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,828 IT Pros & Developers. It's quick & easy.

creating word document using vb6.0

P: 1
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.
Apr 18 '07 #1
Share this Question
Share on Google+
1 Reply


SammyB
Expert 100+
P: 807
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
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private Sub Command1_Click()
  3.     ' Use Project, References menu to add
  4.     ' Microsoft Word & Excel Object Libraries
  5.     Const XL_DOC As String = "N:\Programming\Word\WordTable\InputData.xls"
  6.     Const WD_DOC As String = "N:\Programming\Word\WordTable\ReadMe.doc"
  7.     Dim xlApp As New Excel.Application
  8.     Dim xlBook As Excel.Workbook
  9.     Dim wdApp As New Word.Application
  10.     Dim wdDoc As Word.Document
  11.     Dim wdTable As Word.Table
  12.  
  13.     Set xlBook = xlApp.Workbooks.Open(FileName:=XL_DOC, ReadOnly:=True)
  14.     xlApp.Visible = True
  15.     Set wdDoc = wdApp.Documents.Add
  16.     wdApp.Visible = True
  17.     Set wdTable = wdDoc.Tables.Add(Range:=wdApp.Selection.Range, _
  18.         NumRows:=2, NumColumns:=4, DefaultTableBehavior:=wdWord9TableBehavior, _
  19.         AutoFitBehavior:=wdAutoFitFixed)
  20.     With xlBook.Worksheets("Sheet1")
  21.         wdTable.Cell(1, 1).Range.Text = .Cells(1, 1).Text
  22.         wdTable.Cell(1, 2).Range.Text = .Cells(1, 2).Text
  23.     End With
  24.     'xlApp.Quit
  25.     wdDoc.SaveAs FileName:=WD_DOC
  26.     'wdDoc.Quit
  27. End Sub
Apr 18 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.