The one for RTF turned out to be simply:
Public Function IsRTF(sName As String)
Dim iFileNumber As Integer
Dim sBuffer As String
Dim lCharNumber As Long
Dim sCharacter As String * 1
iFileNumber = FreeFile
Open sName For Binary Access Read Shared As #iFileNumber...
So I figured out the function for JPEG. Still trying to puzzle out the others.
Public Function IsJPG(sName As String)
Dim iFileNumber As Integer
Dim sBuffer As String
Dim lCharNumber As Long
Dim sCharacter As String * 1
iFileNumber = FreeFile
Open sName For Binary Access...
I've discovered that I also need to fix files missing DOT, RTF, TXT, HTM, JPEG, JPG, DOCX, DOCM, XLS, XLSX, XLSM, PPT and PPTX extensions. I'm struggling to see how I can how I can create functions to test for those from the info provided at http://www.garykessler.net/library/file_sigs.html. Is...
This works a treat with a Word doc, thanks. I'll post the whole thing once it's done.
What tags do I use in this site to mark up text as code?
Cheers,
Ged.
Private Sub FixExts()
Dim sFileName As String
Dim sExt As String
sFileName = "H:\ReplaceLostExts\testDOC"
If IsWordDoc(sFileName) =...
Thanks Ben. I've not come across Magic Numbers before. It looks like it could be a more efficient method - I wasn't sure how the code I posted above would cope with large numbers of files. I'll give it a go this evening.
Cheers,
Ged.
The code below now successfully opens the file in Word (if it's a .doc) and then closes Word and returns the file type. I've still got a bit of work ahead of me:
1. Do the same for PDF files
2. Rename the file with the correct extension
3. Set up a loop to work through a table of prath & file...
Thanks for your reply. This is what I've got so far just to test the function returns the right extension. I created a .doc file and saved it as "testDOC". When I run FixExts() I get an empty string returned - any ideas what I'm doing wrong?
Private Sub FixExts()
Dim MyCrummyFileName As...
I have written a VBA script that finds documents missing their file extensions (sloppy users) over a shared drive tree and writes the filename and path into a table.
I now have a list of some 900 documents out of a total 120,000 on the shared drive. Most of those will be Word or pdf format. I...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.