view word file
my program makes a word file and saves it in its respective folder. Now i want the program to open this word file in a form so that i can view the word file it made in VB. Am i making any sense? Please give me suggestions. Thanks!
[230 byte] By [
svn] at [2007-11-11 6:19:50]

# 1 Re: view word file
No problem, you need to read the file to a TextBox, or something thaat will display text (RichTextBox, Label, et cetera).
Here are two functions I wrote to create and read files, to make file handling easy for myself.
Public Function ReadFile(FileDir As String) As String
Dim i As Long, strText As String
i = FreeFile
strText = ""
Open FileDir For Input Lock Write As #i
Screen.MousePointer = vbHourglass
DoEvents
strText = StrConv(InputB$(LOF(i), i), vbUnicode)
Close #i
Screen.MousePointer = vbDefault
ReadFile = strText
End Function
Public Function WriteFile(FileDir As String, WriteData As String) As String
Open FileDir For Output As #1
'Open the file
Write #1, WriteData
Close #1
End Function
I hope that helps.
--Drakenza
# 2 Re: view word file
Here, to make your life even easier, I've attached a module with the functions given above. Download it, unzip it, and add it to your Project
(Project -> Add Module -> Existing -> Folder containg module).
I suggest you save it for use later as well.
# 3 Re: view word file
After a long weekend i finally got back to this! Thank you very much for respnding to my query and for trying to make my life easier. However, i have some problem with the code.
1. The LOF function gives size of the file. I cannot use to that to read the # of characters. eg. the size of the file maybe 3300 (bytes?) but the number of characters in my file could be 91? So that is not working.
2. I put a label and a textbox on my form to see which one would work better. Both of them work well with a txt document. They dont work so well with rtf or with doc extensions. And these files are all just plain text files.
3. what happens if there is a table/graph/picture in my word (rtf or doc) file? I doubt its going to work well with it.
Please let me know if I am understanding this right or am i missing something here? Thanks!
svn at 2007-11-11 17:30:43 >

# 4 Re: view word file
i figured it out. I did it a little different but i guess it worked for me. This is what i did:
1. I put a rich text box control on a form. I set the property of scrollbars to both vertical and horizontal.
2. I also put a button which has the follwoing code:
Private Sub Command1_Click()
Form1.RichTextBox1.LoadFile "C:\Plots.rtf"
End Sub
3. I think this works very well with rtf's. It does not load Doc file extensions. It does only Txt and RTF's.
This works for me. If anyone has any better ideas n how to do this - let me know. Thanks!
svn at 2007-11-11 17:31:40 >

# 5 Re: view word file
Well, glad you figured it out. It worked for me though... I was able to read all kinds of files. Hmmm...
# 6 Re: view word file
i am saving my file as RTF file and that takes quite long (comparing it to saving it as a doc). i am doing:
PtDoc.SaveAs mnfrm.mfolders & "\" & fname & "\Plots.doc"
PtDoc.SaveAs mnfrm.mfolders & "\" & fname & "\Plots.rtf", wdFormatRTF
is there a way to save this rtf file faster.
also, Drakenza, i read that you can load all kinds of files. what control are you using to view the files. I am using Rich text box control.
Thanks ~svn
svn at 2007-11-11 17:33:48 >

# 7 Re: view word file
i figured out the first part. i should do:
PtDoc.SaveAs mnfrm.mfolders & "\" & fname & "\Plots.doc"
PtDoc.SaveAs , wdFormatRTF
amazingly that works very fast.
i still need to figure out part 2.
svn at 2007-11-11 17:34:52 >
