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

Export to Word file from listview in vb6

P: 138
hi all,
i am using vb6 and a listview to display all the records of students.

now i want all the details of each student to be exported in word file.
i exported in a single column. but i wanted to get it in a matrix form. i mean to say three students in each row and then continue.
i mean to say in the following format:
student1 student2 student3
add1 add2 add3
email1 email2 email3

student4 student5 student6
add4 .......... ...............
and so on....

how to do this
i just did one in a row
plz could anybody kindly help me to format the word file as i needed???
with regards,
Jun 17 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,295
Well, the easiest way to learn how to use Word's VBA is recording a macro in word. then you can copy-paste the code to VB6

just a few tips: always refer to the object before any property or method of Word's VBA. And replace the word and ofice constants with its numeric value:


lets say you recorded:

Expand|Select|Wrap|Line Numbers
  1. Sub Macro1()
  2. '
  3. ' Macro1 Macro
  4. ' Macro grabada el 18/06/2008 por XXXXX
  5. '
  6.     Selection.TypeText Text:="Hello World"
  7.     Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
  8.     Selection.Font.Bold = wdToggle
  9.     If Selection.Font.Underline = wdUnderlineNone Then
  10.         Selection.Font.Underline = wdUnderlineSingle
  11.     Else
  12.         Selection.Font.Underline = wdUnderlineNone
  13.     End If
  14. End Sub
To use it in VB6 you'll need something like

Expand|Select|Wrap|Line Numbers
  1. Sub WORDHelloWorld()
  2.     Dim Obj1 As Object
  3.     Set Obj1 = CreateObject("word.application")
  4.     Obj1.Visible = True
  5.     Obj1.Documents.Add
  6.     With Obj1
  7.         .Selection.TypeText Text:="Hello World"
  8.         .Selection.HomeKey Unit:=5, Extend:=1
  9.         .Selection.Font.Bold = 9999998
  10.         If .Selection.Font.Underline = 0 Then
  11.             .Selection.Font.Underline = 1
  12.         Else
  13.             .Selection.Font.Underline = 0
  14.         End If
  15.     End With
  16. End Sub
Well, HTH
Jun 18 '08 #2

Post your reply

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