Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to find file-path of open workbook? | Excel Discussion (Misc queries) | |||
excel 2003 saved file will not open without a blank workbook open | Excel Discussion (Misc queries) | |||
One workbook file will not open in Excel | Excel Worksheet Functions | |||
in excel when I open my workbook the file name is followed | Excel Discussion (Misc queries) | |||
Workbook and sheets have disappeared but file can open | Excel Discussion (Misc queries) |