|
-
Jun 4th, 2001, 01:00 PM
#1
Thread Starter
Addicted Member
Rich Text Box GURU Question
Hello,
1) Does anyone know how to load a word file into a rich text box?
2) Does anyone know how to convert a word document to a Rich Text File type using VB Coding? thanks in advance.
212 will lead you to the truth
-
Jun 4th, 2001, 01:05 PM
#2
2) I found this out by creating a Word macro as I did it.
ActiveDocument.SaveAs FileName:="Doc1.rtf", FileFormat:=wdFormatRTF, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
-
Jun 4th, 2001, 01:17 PM
#3
to expand on martin's code:
you have to pen the file first in word:
VB Code:
Dim OBJ as Object
Set OBJ = CreateObject("word.application")
OBJ.Documents.Open FileName:="[b]C:\PATH\FILENAME.Doc[/b]", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto
OBJ.ActiveDocument.SaveAs FileName:="[b]C:\PATH\FILENAME.RTF[/b]", ", FileFormat _
:=wdFormatRTF, LockComments:=False, Password:="", AddToRecentFiles:=True _
, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
'then your code to open the file
'I think its
RichTextBox.File = "C:\PATH\FILE.rtf"
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 4th, 2001, 01:19 PM
#4
Thread Starter
Addicted Member
First off thanks for the help. where are the breaks? is this using an object?
212 will lead you to the truth
-
Jun 4th, 2001, 01:21 PM
#5
Thread Starter
Addicted Member
Thanks let me see if I can get this to work.
212 will lead you to the truth
-
Jun 4th, 2001, 01:31 PM
#6
Thread Starter
Addicted Member
Is all of this coding neccessary? Will the following work?OBJ.Documents.Open FileName:=wfilename
OBJ.ActiveDocument.SaveAs FileName:=ConvertedName
I was getting an error somewhere in the orginal string.
212 will lead you to the truth
-
Jun 4th, 2001, 01:34 PM
#7
sorry...change
wdFormatRTF to 6
or add in the gen dec section
Private Const wdFormatRTF = 6
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 4th, 2001, 01:42 PM
#8
Thread Starter
Addicted Member
The code is still failing on the section that opens the doc.
Here is what I have so far:
'Gen dec
Private wFileName As String
Private Const wdFormatRTF = 6
Private Sub Command2_Click()
Dim OBJ As Object
Dim docNew As Object
Dim rtfDoc As Object
Dim c
Dim Txt$
Dim ConvertedName As String
CMDialog1.InitDir = App.Path
CMDialog1.Filter = "Text Files|*.Txt|Rich Text Files|*.rtf|Word Document|*.doc|All Files|*.*"
CMDialog1.FilterIndex = 3
CMDialog1.Flags = 3
CMDialog1.Action = 1
If CMDialog1.FileName = "" Then
Exit Sub
End If
wFileName = CMDialog1.FileName
txtOriginalFileName.Text = wFileName
'****************************************************
Txt$ = wFileName
For i = 1 To Len(Txt$)
c = Mid$(Txt$, i, 1)
If c = "." Then
ConvertedName = ConvertedName + ".rtf"
MsgBox ConvertedName
Exit For
Else
ConvertedName = ConvertedName + c
End If
Next
Set OBJ = CreateObject("word.application")
'The error occurs in the section below
OBJ.Documents.Open FileName:=wFileName, _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto
OBJ.ActiveDocument.SaveAs FileName:=ConvertedName, FileFormat _
:=wdFormatRTF, LockComments:=False, Password:="", AddToRecentFiles:=True _
, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
'then your code to open the file
'I think its
rtbDisplay.LoadFile (ConvertedName)
End Sub
212 will lead you to the truth
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|