View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default verify a path exists

I could use Insert|object and browse to my MIDI file to insert it into a
worksheet (and hide that worksheet later).

Then I could use:

Option Explicit
Sub testme()

Dim OLEObj As OLEObject
Set OLEObj = Worksheets("sheet1").OLEObjects("object 1")
OLEObj.Verb

End Sub

But in xl2003, I was prompted with security questions to allow this potentially
harmful program to play. And then it opened up in my default MIDI player
(WinAmp for me).

I'm not sure you've seen this, but John Walkenbach can help:
http://www.j-walk.com/ss/excel/tips/tip59.htm

Stolen from his site:

Example: Playing a MIDI File
If the sound file is a MIDI file, you'll need to use a different API call. The
PlayMIDI subroutine starts playing a MIDI file. Executing the StopMIDI
subroutine will stop playing the MIDI file.

Private Declare Function mciExecute Lib "winmm.dll" _
(ByVal lpstrCommand As String) As Long
Sub PlayMIDI()
MIDIFile = "xfiles.mid"
MIDIFile = ThisWorkbook.Path & "\" & MIDIFile
mciExecute ("play " & MIDIFile)
End Sub

Sub StopMIDI()
MIDIFile = "xfiles.mid"
MIDIFile = ThisWorkbook.Path & "\" & MIDIFile
mciExecute ("stop " & MIDIFile)
End Sub





JLGWhiz wrote:

The purpose of the check is to see if the file exists on someone elses
computer. I have a novelty program that I have written using Excel that
plays part of a midi file and if the recipient does not have the same
location, I can avoid an error message by using the If ... Then method to
first check for the path. It does not make any difference what the midi file
is, as long as there is one at that location. So what you pointed me to is
what I needed. My only other alternative would be to figure out how to
incorporate the sound into the workbook and that is over my head.

"Dave Peterson" wrote:

That will return something if there is a file with the extension of .mid.

But it's really not a good check to see if a folder exists (just to stress a
very minor point).



JLGWhiz wrote:

Nope just 71 in Oct. I used the Dir() function but I found that the back
slash and a file name are required to make it work right.

exmpl: teststr = Dir("C:\Windows\Media\*.mid") . This gives me specific
info to make the program run right.

Thanks again.

"Dave Peterson" wrote:

Man, I hope you're not 80.

The first 9 years would have been tough!

JLGWhiz wrote:

Thanks Dave, I knew it was not that hard, but my 71 year old brain don't
function too well sometimes.

"Dave Peterson" wrote:

I do this:

Dim TestStr as string

teststr = ""
on error resume next
teststr = dir("c:\windows\media\nul")
on error goto 0

if teststr = "" then
'doesn't exist
else
'it's there
end if

====
But this'll work, too:

If CreateObject("Scripting.FileSystemobject") _
.folderexists("C:\windows\media") = True Then
MsgBox "Yep"
Else
MsgBox "nope"
End If

JLGWhiz wrote:

This is probably so simple that I am overlooking it. I want to write code as
an If...Then method to verify that a certain path exists. Let's say
"C:\Windows|Media".
I tried the Exists( What ) method but could not find an object that VBA
liked. Make me feel stupid and show me the code. Thanks.

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson