Results 1 to 5 of 5

Thread: Opening word documents in vb

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    107

    Opening word documents in vb

    I've got some corrupted files, RTF (rich text format) ones that were saved as .doc. In my Vb project I need to make sure that a .doc file really is a .doc one and not an RTF one with the wrong extension. How can I do that?

    Thanks

    Kati

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Opening word documents in vb

    Well you could check the files extension but this would prove nothing. The only other way you could find out it drop them into notepad .rtf documents are mostly text and start with something like

    {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}

    That may be time consuming depending on the number of documents but you could also write some code that checks the first couple bytes of the file. I know .doc documents start with a header like ÐÏ à¡ but I maybe wrong you really need to look up on the format it’s self
    When your dreams come true.
    On error resume pulling hair out.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    107

    Re: Opening word documents in vb

    Can you please give me an example of how to open a .doc and check first bytes in vb?

  4. #4
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Opening word documents in vb

    hi try this. but bare in mind this is not the correct way. you really need to read on the format but if you only want it for basic stuff I shoud be ok.

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim iFile As Long
    3. Dim sHead As String
    4.     sHead = Space(4)
    5.    
    6.     iFile = FreeFile
    7.     Open "C:\test.doc" For Binary As #iFile
    8.         Get #iFile, , sHead
    9.     Close #iFile
    10.    
    11.     If Not sHead = "ÐÏà" Then
    12.         MsgBox "Is Not Word Document"
    13.     Else
    14.         MsgBox "Is Word Document File"
    15.     End If
    16.    
    17.     sHead = ""
    18.    
    19. End Sub
    When your dreams come true.
    On error resume pulling hair out.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    107

    Re: Opening word documents in vb

    thanks a lot!!

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