Skip to content

Instantly share code, notes, and snippets.

@darkdreamingdan
Last active May 10, 2016 21:43
Show Gist options
  • Save darkdreamingdan/8264fe36be213a254a7e2ed1d9c9314e to your computer and use it in GitHub Desktop.
Save darkdreamingdan/8264fe36be213a254a7e2ed1d9c9314e to your computer and use it in GitHub Desktop.
Play a sound embedded as an OLEObject in Excel #OLEObjectsinVBA
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