Results 1 to 14 of 14

Thread: editor prob

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    87

    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

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    .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:
    1. 'The document is inside a frame on the form, rather than on the form itself.
    2. Private Declare Function SetParent Lib "User32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    3. 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
    4.  
    5. Private oWord As Word.Application
    6. Private oDoc As Word.Document
    7.  
    8. Private Sub Command1_Click()
    9.     Dim oWord As Word.Application
    10.     Dim oDoc As Word.Document
    11.     Dim WinHandle As Long
    12.    
    13.     Set oWord = CreateObject("Word.Application")
    14.     oWord.Documents.Open FileName:="c:\temp\Test.doc"
    15.     oWord.Documents("Test.doc").Activate
    16.     oWord.Visible = True
    17.    
    18.     Set oDoc = oWord.ActiveDocument
    19.     WinHandle = FindWindowEx(0&, 0&, vbNullString, "Test.doc - Microsoft Word")    
    20.     SetParent WinHandle, Frame1.hWnd
    21. End Sub
    22.  
    23. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    24. Set oWord = Nothing
    25. Set oDoc = Nothing
    26. 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:
    1. Private Sub Form_Load()
    2.     Me.Move 0, 0, Screen.Width, Screen.Height
    3.     OLE1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
    4.     Me.Visible = True
    5.     OLE1.AutoActivate = vbOLEActivateManual
    6.     OLE1.Class = "Word.Document.8" 'depends on what's installed on your system
    7.     OLE1.CreateEmbed "C:\My Documents\test.doc"
    8.     OLE1.DoVerb vbOLEUIActivate
    9.     OLE1.Visible = True
    10. End Sub

  3. #3
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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....

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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:
    1. Option Explicit
    2. Private objWord As Word.Application
    3. Private wd As Word.Document
    4.  
    5. Private Sub Command1_Click()
    6.     If objWord Is Nothing Then
    7.         Set objWord = CreateObject("Word.Application")
    8.     Else
    9.         Set objWord = GetObject(, "Word.Application")
    10.     End If
    11.     DoEvents
    12.     Set wd = objWord.Documents.Open("c:\Test.doc")
    13.  
    14. ' Here you can step through the complete document, or select a sub-range.
    15. ' I haven't done this! so someone else will need to supply the code to:
    16. ' For each paragraph in objWord.Document
    17. '  myTextBox = myTextBox & paragraph & vbCRLF & vbCRLF
    18.  
    19.  
    20.    'objWord.Visible = True
    21.     If Not (wd Is Nothing) Then Set wd = Nothing
    22.     If Not (objWord Is Nothing) Then objWord.Application.Quit
    23.     If Not (objWord Is Nothing) Then Set objWord = Nothing
    24. end sub

  5. #5
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Just use a rich text box... far easier.
    Don't Rate my posts.

  6. #6
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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.

  7. #7
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Yeah, he pmed me as well.. and I told him to just use

    VB Code:
    1. commondialog1.showopen
    2. Richtextbox1.filename = commondialog1.filename

    If he pm's me again, I'm blocking him..
    Don't Rate my posts.

  8. #8
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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:
    1. Dim WordApp As Word.Application
    2. Set WordApp = New Word.Application
    3. Set WordDoc = WordApp.Documents.Open("MyFileToOpen.doc")
    4.     WordApp.Visible = False
    5.     WordApp.ActiveDocument.SaveAs FileName:="MyFileToSave.txt", FileFormat:=wdFormatText, _
    6.         LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
    7.         :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
    8.         SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
    9.         False
    10.     WordDoc.Close False
    11.     WordApp.Quit False
    12. Set WordApp = Nothing

  9. #9
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    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:
    1. Dim WordApp As Word.Application
    2. Set WordApp = New Word.Application
    3. Set WordDoc = WordApp.Documents.Open("MyFileToOpen.doc")
    4.     WordApp.Visible = False
    5.     WordApp.ActiveDocument.SaveAs FileName:="MyFileToSave.txt", FileFormat:=wdFormatText, _
    6.         LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
    7.         :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
    8.         SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
    9.         False
    10.     WordDoc.Close False
    11.     WordApp.Quit False
    12. 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.
    Don't Rate my posts.

  10. #10
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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.

  11. #11
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    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...
    Don't Rate my posts.

  12. #12
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    OK, Thanks.
    I was trying to view "non-plain text".

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    87

    editor

    hello
    thanx jordan thanx for ur help
    bye

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    87

    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
  •  



Click Here to Expand Forum to Full Width