Play any audio file using VBA Excel

前端 未结 5 1676
独厮守ぢ
独厮守ぢ 2021-01-26 20:52

I have a piece of code which can read most audio files (including wav, mp3, midi...), but it won\'t work if there are spaces in the path or File name.

so I have to revert

5条回答
  •  感动是毒
    2021-01-26 21:41

    Go old-school...think DOS.
    For example:
    "C:\Way Too Long\Long Directory\File.mp3"
    becomes
    "C:\WayToo~1\LongDi~1\File.mp3"

    The trick is to get rid of spaces and keep directories and filenames under 8 characters. To do this, remove all spaces, then truncate after the first 6 characters and add a tilde (~) plus the number one.
    I tried this method and it worked perfectly for me.

    One thing to be cautious of is that if there is a chance of ambiguity in a shortened directory name (like "\Long File Path\" and "\Long File Paths\" and "\Long File Path 1436\") then you'll need to adjust the number after the tilde ("\LongFi~1\" and "\LongFi~2\" and "\LongFi~3\", in the order in which the directories were created).

    Therefore, it is possible that a previous folder was called "FilePa~1" and was deleted while a similarly named "FilePa~2" was left. So your file path may not automatically be suffixed with a "~1". It might be "~2" or something higher, depending on how many similarly named directories or filenames there were.

    I find it incredible that dos was released 35 years ago, and VBA programmers are still having to deal with this dinosaur of a problem with directories!

提交回复
热议问题