|
-
Aug 26th, 2005, 09:29 AM
#1
Thread Starter
Lively Member
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
-
Aug 26th, 2005, 09:50 AM
#2
Hyperactive Member
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.
-
Aug 26th, 2005, 10:00 AM
#3
Thread Starter
Lively Member
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?
-
Aug 26th, 2005, 10:24 AM
#4
Hyperactive Member
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:
Private Sub Command1_Click()
Dim iFile As Long
Dim sHead As String
sHead = Space(4)
iFile = FreeFile
Open "C:\test.doc" For Binary As #iFile
Get #iFile, , sHead
Close #iFile
If Not sHead = "ÐÏà" Then
MsgBox "Is Not Word Document"
Else
MsgBox "Is Word Document File"
End If
sHead = ""
End Sub
When your dreams come true.
On error resume pulling hair out.
-
Aug 26th, 2005, 10:48 AM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|