問題已縮小到一行。這是絕對路徑和相對路徑之間的問題。
此行有效: PlayWavFile "c:\TransmissionFile\AWNP.wav", False
我更喜歡這樣的東西,但它不起作用: PlayWavFile "AWNP.wav", False
我在 C 驅動器和程式所在的檔案夾中都有波形檔案。所以為了程式檔案夾是可移植的,我想使用相對路徑。我怎么做?怎么了?
uj5u.com熱心網友回復:
嘗試這個:
Dim CurrentFolder As String
CurrentFolder = ThisWorkbook.Path
PlayWavFile CurrentFolder & Application.PathSeparator & "AWNP.wav", False
uj5u.com熱心網友回復:
你的問題留下了一些懸而未決的問題。但是,采用最佳猜測方法,我認為這就是您的目標:
Option Explicit
' assuming this is the Lib declaration:
Public Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
' and assuming this is the sub format you're using to call (as declared) sndPlaySound
Sub PlayWavFile(WavFileName As String, Wait As Boolean)
' Set path based on this workbook's folder location
Dim stFilePath$: stFilePath = ThisWorkbook.Path & "\" & WavFileName
' If file is missing, try root of C drive
If Dir(stFilePath) = "" Then
stFilePath = "C:\" & WavFileName
' Not here either: report and end
If Dir(stFilePath) = "" Then
MsgBox WavFileName & " not found"
Exit Sub
End If
End If
' Play the sound (with/without wait)
If Wait Then
sndPlaySound stFilePath, 0
Else
sndPlaySound stFilePath, 1
End If
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/365344.html
上一篇:檢查對單元格的參考是否有效
