Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default VBA for XL95, Workbook.open non XL-file

Wouter

One thing you can do is read the document properties. See Chip's site for
reading properties from a closed file

http://www.cpearson.com/excel/docprop.htm

If the file is an Excel file, the AppName property will return Microsoft
Excel. Here's an example

Sub test()

Dim Fname As String
Dim wb As Workbook
Dim DSO As DSOleFile.PropertyReader
Dim ErrorGrab As String

Fname = "c:\Downloads\dsofile.exe"
Set DSO = New DSOleFile.PropertyReader

ErrorGrab = DSO.GetDocumentProperties(Fname).AppName

If ErrorGrab = "Microsoft Excel" Then
Set wb = Workbooks.Open(Fname)
End If

End Sub

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com

"Wouter" wrote in message
om...
Hi there,

I have written a VBA macro which scans all the directories of a drive.

In code:

Sub Start
Dim strDrive As String
StrDrive = InputBox(?Which drive?)
Call ScanDir(strDrive)
End Sub

Sub ScanDir(ByVal strDir As String)
Dim strNew As String
Dim strFile As String
strFile = Dir(strDir, vbDirectory)
Do While Left$(strFile, 1) = ?.?
strFile = Dir()
Loop
Do While Len(strFile) 0
If (GetAttr(strDir & strFile) And vbDirectory) = vbDirectory Then
Call ScanDir(strDir & strFile)
StrNew = Dir(strDir, vbDirectory)
Do While strNew < StrFile
StrNew = Dir()
Loop
Else
If Ucase(Left$(right$(strFile,3),2)) = ?XL? Then
Call ScanWorkBook(strFile, strDir)
EndIf
Endif
Dir()
Loop
End Sub

Sub ScanWorkbook(ByVal StrFile as String, ByVal strPath as String)
On Local Error Goto ThisSub_Err
Workbooks.Open filename:=strPAth & strFile , UpdateLink:=0,

ReadOnly:=False
With Workbooks(strFile)
' Do this and that
.Saved = True
.Close
End With
Goto ThisSub_exit
ThisSub_Err:
Msgbox Err
ThisSub_exit:
End Sub

1) If it finds a file with the extension XL? It tries to open it
and look inside for some specific components, Not the prolem

The macro has found e file with he extension XLT but it is
not a Excel Template.
When the process reaches the WorkBooks.Open command I get a
Dialog which report that I van not recognize the binary file.

Any Idea how to solve this so the macro continues running and
does not ask what to do with the files that are not recognized?


2) Is there a way to optimize the code to scan the driectory and
all its subdirectories?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find file-path of open workbook? Larryq22 Excel Discussion (Misc queries) 7 January 24th 08 03:38 AM
excel 2003 saved file will not open without a blank workbook open Bob Excel Discussion (Misc queries) 4 November 11th 06 04:24 PM
One workbook file will not open in Excel T2010 Excel Worksheet Functions 0 January 8th 06 05:05 AM
in excel when I open my workbook the file name is followed ls50317 Excel Discussion (Misc queries) 1 February 9th 05 08:29 PM
Workbook and sheets have disappeared but file can open Jacktion Excel Discussion (Misc queries) 4 January 27th 05 02:11 PM


All times are GMT +1. The time now is 07:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"