ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Identify an Word/Excel file without the doc/xls extension (https://www.excelbanter.com/excel-programming/288050-identify-word-excel-file-without-doc-xls-extension.html)

Rui Oliveira

Identify an Word/Excel file without the doc/xls extension
 
Hi,

How can I know if a file is an Word/Excel file, when the
file does not have the doc/xls extension?

I have a folder with a lot of files and all them without
extension (xls, doc, txt, .). How can I know witch these
files are Word or Excel files?

Thanks,

Rui


Perry

Identify an Word/Excel file without the doc/xls extension
 
You cud try something like:

From Word VBA

Dim o As Object, fName As String
With Application.FileSearch
.NewSearch
.LookIn = "c:\temp\test"
.FileName = "*.*"
.Execute
For x = 1 To .FoundFiles.Count
fName = .FoundFiles(x)
Set o = GetObject(fName)
On Error GoTo ErrUnkown
Debug.Print fName, o.Parent
Next
End With
Set o = Nothing
Exit Sub
ErrUnkown:
Debug.Print fName, "Unkown"
Resume Next

Resulting in following lines in the Immediate Window
C:\temp\test\NoExtensionWD Microsoft Word
C:\temp\test\NoExtensionXL Microsoft Excel

Note: files have no extension.

Krgrds,
Perry

"Rui Oliveira" wrote in message
...
Hi,

How can I know if a file is an Word/Excel file, when the
file does not have the doc/xls extension?

I have a folder with a lot of files and all them without
extension (xls, doc, txt, .). How can I know witch these
files are Word or Excel files?

Thanks,

Rui





All times are GMT +1. The time now is 09:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com