|
-
Oct 7th, 2002, 01:41 AM
#1
Thread Starter
Lively Member
editor prob
hello everybody
how can i open a .doc file through commondialog in a text box as i can open a txt file...
i have the screen shot of the editor which i need to apply...
www.geocities.com/coolprem_555
pls help me
thanx bye bye
-
Oct 7th, 2002, 04:41 AM
#2
Frenzied Member
.DOC files could be Rich Text Format - so use a RichTextBox, rather than a normal Text Box.
Alternatively, look at embedding Word into your application:
VB Code:
'The document is inside a frame on the form, rather than on the form itself.
Private Declare Function SetParent Lib "User32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function FindWindowEx Lib "User32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private oWord As Word.Application
Private oDoc As Word.Document
Private Sub Command1_Click()
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim WinHandle As Long
Set oWord = CreateObject("Word.Application")
oWord.Documents.Open FileName:="c:\temp\Test.doc"
oWord.Documents("Test.doc").Activate
oWord.Visible = True
Set oDoc = oWord.ActiveDocument
WinHandle = FindWindowEx(0&, 0&, vbNullString, "Test.doc - Microsoft Word")
SetParent WinHandle, Frame1.hWnd
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Set oWord = Nothing
Set oDoc = Nothing
End Sub
To embed a document within your own application, it might be better to use the OLE control, rather than the SetParent API as above.
VB Code:
Private Sub Form_Load()
Me.Move 0, 0, Screen.Width, Screen.Height
OLE1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
Me.Visible = True
OLE1.AutoActivate = vbOLEActivateManual
OLE1.Class = "Word.Document.8" 'depends on what's installed on your system
OLE1.CreateEmbed "C:\My Documents\test.doc"
OLE1.DoVerb vbOLEUIActivate
OLE1.Visible = True
End Sub
-
Oct 7th, 2002, 09:43 AM
#3
Frenzied Member
RE:
my code which i use to open a text file:
Code:
Private Sub Command3_Click()
On Error Resume Next
CommonDialog1.Filter = "Text Files|*.txt|All Files|*.*"
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
fnum = FreeFile
Open CommonDialog1.FileName For Input As #fnum
allTxt = Input(LOF(fnum), #fnum)
Close fnum
Text1.Text = allTxt
End Sub
this code opens a txt file in the text box
as u told i am using a rich textbox...but i facin some errors
but how do i open the file in the richtextbox.....if possible by this method...
the first code of yours opens a doc file in the mic word application
and the second one i tried the word applications menu and all are appearing...and seems that one is very heavy for the application as it flickers while opening it.......
so pls help me in this
============================================
To use the RichTextBox control, just don't need to read the file into a variable first, you just set:
RichTextBox1.FileName = "YourFileName.RTF"
But the file needs to be in RTF format. This is not the same as a .DOC file, which is in Word format.
If you want to display a Word document, then you need something that can understand the Word format - hence the OLE control, or embedding of Word.
Of course, you could go complex and se Word Automation to read each line from a Word document, and then display each line back into a text box....
-
Oct 8th, 2002, 04:42 AM
#4
Frenzied Member
From premz: (PLEASE reply in the forum so others can help, not via private e-mail).
i understood a little bit abt word ,rtf.....
so how is that possible that u said to read a single line from the selected word doc and then transfer to a textbox....ie word automation.......canu help in this
i am wondering that how is this possible with the editor u saw before in a jpg.....it opens a word doc file and a winword instance is running behind(hidden) and copies a full text in a particular text....
so pls help me
IF you open Word in Word Automation, it would be possible to get a word / line / paragraph of text, and put that into a text box. But editing it and putting it back into the Word document would not be sensible - as all attributes would be lost and not displayed in the text box. Instead, you would have to save the results of the text only changes made in the text box to a new ASCII .TXT file.
Not knowing why you need to edit the files, and what you are editting, I can not advise as to whether this is a suitable approach.
IF you need to open Word, this will get some of the way:
VB Code:
Option Explicit
Private objWord As Word.Application
Private wd As Word.Document
Private Sub Command1_Click()
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
Else
Set objWord = GetObject(, "Word.Application")
End If
DoEvents
Set wd = objWord.Documents.Open("c:\Test.doc")
' Here you can step through the complete document, or select a sub-range.
' I haven't done this! so someone else will need to supply the code to:
' For each paragraph in objWord.Document
' myTextBox = myTextBox & paragraph & vbCRLF & vbCRLF
'objWord.Visible = True
If Not (wd Is Nothing) Then Set wd = Nothing
If Not (objWord Is Nothing) Then objWord.Application.Quit
If Not (objWord Is Nothing) Then Set objWord = Nothing
end sub
-
Oct 8th, 2002, 05:39 AM
#5
PowerPoster
Just use a rich text box... far easier.
-
Oct 9th, 2002, 04:47 AM
#6
Frenzied Member
He says:
i cannot post a new thread nor post rply from my machine don't know why.....but pm was working.....
see i am havin a recruitment's project
and he want the registration form ....and this is done ...but in the later half he wants to open a word file which contains the candidate's resume ...and the file to be store .... as u saw in the jpg ......this is the whole situation talkin abt....so i am stuck
so i don't know wht to do
bye
waitin for ur reply
If the candidate has sent in a Word file, then that file should be opened in Word. Opening it in anything else could cause format changes or ignore useful data.
You can do one of:
- Use Word Automation to extract text.
- Use OLE to embed the Word application onto your form.
- ShellExecute the .DOC file, and launch the Word application.
-
Oct 9th, 2002, 04:56 AM
#7
PowerPoster
Yeah, he pmed me as well.. and I told him to just use
VB Code:
commondialog1.showopen
Richtextbox1.filename = commondialog1.filename
If he pm's me again, I'm blocking him..
-
Oct 9th, 2002, 05:26 AM
#8
Frenzied Member
And if the .DOC doesn't view properly in a RichTextBox (as its Word format, rather than RTF format), you can always do something quick in Word to save the file to a .TXT file, and then it can display in a standard TextBox as well. E.g.:
VB Code:
Dim WordApp As Word.Application
Set WordApp = New Word.Application
Set WordDoc = WordApp.Documents.Open("MyFileToOpen.doc")
WordApp.Visible = False
WordApp.ActiveDocument.SaveAs FileName:="MyFileToSave.txt", FileFormat:=wdFormatText, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
WordDoc.Close False
WordApp.Quit False
Set WordApp = Nothing
-
Oct 9th, 2002, 05:31 AM
#9
PowerPoster
Originally posted by JordanChris
And if the .DOC doesn't view properly in a RichTextBox (as its Word format, rather than RTF format), you can always do something quick in Word to save the file to a .TXT file, and then it can display in a standard TextBox as well. E.g.:
VB Code:
Dim WordApp As Word.Application
Set WordApp = New Word.Application
Set WordDoc = WordApp.Documents.Open("MyFileToOpen.doc")
WordApp.Visible = False
WordApp.ActiveDocument.SaveAs FileName:="MyFileToSave.txt", FileFormat:=wdFormatText, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
WordDoc.Close False
WordApp.Quit False
Set WordApp = Nothing
???? Leave the bloody word thing alone..
DOC's should display reasonably well in a RichTextbox, and if they don't ?? Its not meant to be opened in other Text Editors, so...??
Although, I've never had any trouble with it.
-
Oct 9th, 2002, 05:40 AM
#10
Frenzied Member
DOC's should display reasonably well in a RichTextbox, and if they don't ??
That's just what I thought, when I started trying to help this PMer. But, if I put RichTextBox.FileName=MyDoc.DOC all I get is lots of hieroglyphics.
Is there another parameter I have to set to get a RichTextBox to display a Word document? RichTextBox from Microsoft Rich Textbox Control 6.0, .DOC from Word 2000.
-
Oct 9th, 2002, 05:43 AM
#11
PowerPoster
If its plain text inside the doc, it will display it. Personnelly, I wouldn't give pfft if the user wants to open a doc. Its not your extension, its only for one product. If you really want, make the user a Doc to RTF convertor, so that user gets the hint that if you save it as .rtf it will be compatible in all editors.
I guess it all depends on how much you want to support a microsoft product...
-
Oct 9th, 2002, 05:46 AM
#12
Frenzied Member
OK, Thanks.
I was trying to view "non-plain text".
-
Oct 9th, 2002, 06:17 AM
#13
Thread Starter
Lively Member
editor
hello
thanx jordan thanx for ur help
bye
-
Oct 9th, 2002, 06:21 AM
#14
Thread Starter
Lively Member
editor
thanx jrdan for ur help thnx alot....
suddenly my reply post worked.....sorry for pm ing u all....sorry
i will try to to open a rtfile rather than a doc file
and thnx pcmadness to u 2
thnx sorry for the trouble
bye
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
|