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.
Printable View
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.
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
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"
First off thanks for the help. where are the breaks? is this using an object?
Thanks let me see if I can get this to work.
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.
sorry...change
wdFormatRTF to 6
or add in the gen dec section
Private Const wdFormatRTF = 6
:D
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