Last active
May 10, 2016 21:43
-
-
Save darkdreamingdan/8264fe36be213a254a7e2ed1d9c9314e to your computer and use it in GitHub Desktop.
Play a sound embedded as an OLEObject in Excel #OLEObjectsinVBA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub CommandButton1_Click() | |
Dim EmbeddedFileName As String | |
Dim obj As OLEObject | |
' Loop through all our OLE Objects to find the one we want. | |
For Each obj In OLEObjects | |
' If it's our success sound... | |
If InStr(obj.Name, "sound_success") <> 0 Then | |
' We try to grab the embedded file name. We call this twice. | |
EmbeddedFileName = Module1.GetOLETempPath(obj) ' Once to create the file | |
EmbeddedFileName = Module1.GetOLETempPath(obj) ' Then to grab the filename | |
If EmbeddedFileName = "" Then | |
MsgBox "Something went wrong!" | |
Exit Sub | |
End If | |
End If | |
Next | |
' Now we have EmbeddedFileName, you can play this with something like Call sndPlaySound32(EmbeddedFileName, 0) | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment