View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
LFCFan[_2_] LFCFan[_2_] is offline
external usenet poster
 
Posts: 1
Default Determine file type


David,

I tinkered with my code a bit, it will now open any of the 3 file types
in the right app. Feel free to mod it for your own use.

Sub chFType()
Set fObj = CreateObject("scripting.filesystemobject")
Set dObj = CreateObject("wscript.shell")
dObj.Run "c:\winnt\system32\cmd.exe /c dir c:\ /D c:\testfTypes.txt",
0, True


Set rFile = fObj.opentextfile("C:\testfTypes.txt", 1, False)

Do Until rFile.atendofstream
currLine = rFile.readLine
getDot = InStr(1, currLine, ".")
lookRight = Right(currLine, 1)
If getDot 0 And lookRight < "." Then
dotExists = Mid(currLine, getDot, 4)
If dotExists = ".xls" Then
xlsMsg = MsgBox("I found an excel file! Its called " & currLine
& Chr(13) & Chr(13) & "Would you like to open it?", vbYesNo)
If xlsMsg = vbYes Then
dObj.Run ("c:\winnt\system32\cmd.exe /c start excel c:\") &
currLine
End If
ElseIf dotExists = ".txt" Then
txtAsk = MsgBox("I found a text file! Its called " &
currLine & Chr(13) & Chr(13) & "Would you like to Open it?", vbYesNo)
If txtAsk = vbYes Then
dObj.Run ("c:\winnt\system32\cmd.exe /c start
notepad.exe c:\") & currLine
End If
ElseIf dotExists = ".doc" Then
wrdAsk = MsgBox("I found a word document!
Its called " & currLine & Chr(13) & Chr(13) & "Would you like to open
it?", vbYesNo)
If wrdAsk = vbYes Then
dObj.Run
("c:\winnt\system32\cmd.exe /c start winword c:\") & currLine
End If
Else
MsgBox "The file: " & currLine & " is not word, Excel or Text!"
End If
End If


Loop

End Sub

Cheers
Joe


--
LFCFan
------------------------------------------------------------------------
LFCFan's Profile: http://www.excelforum.com/member.php...o&userid=37484
View this thread: http://www.excelforum.com/showthread...hreadid=571368