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

i need print report in Msword

P: 10
hi dear
i want to Display report in Msword (.doc) can it possible.
in vb6 i display some info in form using label controls.
when i press report button it show in ms word file.
if possible then plz give me code.


[email removed]



plz Help me Soon
Apr 17 '07 #1
Share this Question
Share on Google+
3 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
This post is being moved to the Visual Basic forum.

ADMIN
Apr 17 '07 #2

hariharanmca
100+
P: 1,977
hi dear
i want to Display report in Msword (.doc) can it possible.
in vb6 i display some info in form using label controls.
when i press report button it show in ms word file.
if possible then plz give me code.


[email removed]



plz Help me Soon

Yes itz possible, But i don't have time to give now...
Apr 17 '07 #3

hariharanmca
100+
P: 1,977
hi dear
i want to Display report in Msword (.doc) can it possible.
in vb6 i display some info in form using label controls.
when i press report button it show in ms word file.
if possible then plz give me code.


[email removed]



plz Help me Soon
Expand|Select|Wrap|Line Numbers
  1. Dim i As Long
  2. Dim strLineText() As String
  3.  
  4.  
  5.  
  6. Private Sub Command2_Click()
  7.     TextBox1.LoadFile ("D:\Reports\Report.txt")
  8.     send_TO_WordFile TextBox1
  9. End Sub
  10.  
  11. Private Sub send_TO_WordFile(pRichTextBox As RichTextBox)
  12.     Dim objWord As New Word.Application
  13.     Dim thisDoc As New Word.Document
  14.     Dim thisRange As Word.Range
  15.     Dim lngI As Long
  16.     Dim lngNoLines As Long
  17.     Set objWord = CreateObject("Word.Application")
  18.     Set thisDoc = objWord.Documents.Add
  19.     If Err.Number Then
  20.         Err.Clear
  21.         Set objWord = CreateObject("Word.Application")
  22.     End If
  23.     objWord.Visible = True
  24.     lngNoLines = SplitLineString(pRichTextBox.Text)
  25.     For lngI = 0 To lngNoLines - 1
  26.         thisDoc.Range.InsertAfter strLineText(lngI)
  27.         lngNoLines = thisDoc.Paragraphs.Count - 1
  28.         Set thisRange = thisDoc.Paragraphs(lngI + 1).Range
  29.         thisRange.Font.Name = "Courier New"
  30.         thisRange.Font.Size = 8
  31.         thisRange.Font.Bold = PrintBold(strLineText(lngI), lngI)
  32.         thisRange.Font.Underline = False
  33.     Next lngI
  34.     thisDoc.SaveAs (App.Path & "\Repo.doc")
  35.     End Sub
  36.  
  37.  
  38. Private Function SplitLineString(pStrText As String) As Long
  39.     Dim line As String
  40.     Dim lngNoLines As Long
  41.     line = "" & vbCr & ""
  42.     lngNoLines = UBound(Split(pStrText, line))
  43.     ReDim strLineText(lngNoLines) As String
  44.     strLineText = Split(pStrText, line)
  45.     SplitLineString = lngNoLines
  46. End Function
  47.  
  48.  
  49. Private Function PrintBold(pStrText As String, pLineNo As Long) As Boolean
  50.     If pLineNo <= 2 Then PrintBold = True: Exit Function
  51.     If Mid(Trim(strLineText(pLineNo - 1)), 5, 8) = Mid(Trim(String(142, "-")), 5, 8) And Mid(Trim(strLineText(pLineNo + 1)), 5, 8) = Mid(Trim(String(142, "-")), 5, 8) Then
  52.         For i = 1 To Len("0123456789")
  53.             If InStr(1, Trim(pStrText), Mid("0123456789", i, 1)) <= 0 Then
  54.                 PrintBold = True
  55.             Else
  56.                 PrintBold = False
  57.                 Exit Function
  58.             End If
  59.         Next i
  60.     End If
  61. End Function
the above is one sample which will load the text file content to rich text box
and to MS word document change the code and use it
Apr 17 '07 #4

Post your reply

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