1

I'm trying to populate an Excel worksheet with controls that will play audio file examples of how to pronunce a list of words.

If the content of A1 is "introduce", I want Excel to play an audio file named introduce.m4a when (say) a button in B1 is pressed. I don't want the sound played by an external app or another browser window.

I've found a fair bit of VBA code that plays a sound triggered by events in an Excel worksheet, but none that gets the name of the audio file from a cell in the sheet.

Sub Playm4a()
   Application.ScreenUpdating = False
   On Error Resume Next
   ActiveSheet.OLEObjects.Add(Filename:=ActiveCell.Text, Link:=True).Select
   If Err.Number <> 0 Then
     Application.ScreenUpdating = True
     MsgBox "Could not play " & ActiveCell.Text
     Exit Sub
   End If
   Selection.Verb
   Selection.Delete
End Sub

Thanks in advance for any help!

4
  • Please add the relevant part of the code sample to the question.
    – nohillside
    May 13, 2016 at 11:53
  • I don't have any code yet, because I don't know how to make the core part of the routine work. Suppose I have a sound file <Macinosh HD/Users/David/Desktop/words/thanks.m4a> and the content of cell A1 is "Macinosh HD/Users/David/Desktop/words/thanks.m4a" What VBA code will cause that sound to be played? May 15, 2016 at 11:17
  • Your question says "I've found a fair bit of code…" so I assume you already have code which plays a sound and are now looking for a way to replace the sound file used there by a path/file from a cell. How does this code look like? (Background: it's a lot easier to change existing macros than writing new ones from scratch)
    – nohillside
    May 15, 2016 at 12:37
  • Yes indeed! It's easier to modify than start from scratch. But I don't know what needs to be modified in this: Sub Playm4a() Application.ScreenUpdating = False On Error Resume Next ActiveSheet.OLEObjects.Add(Filename:=ActiveCell.Text, Link:=True).Select If Err.Number <> 0 Then Application.ScreenUpdating = True MsgBox "Could not play " & ActiveCell.Text Exit Sub End If Selection.Verb Selection.Delete End Sub May 16, 2016 at 21:52

1 Answer 1

2

Found this question when tried to solve the similar problem (creating a vocabulary notebook for learning english words). The easiest solution for me was just to use built-in voice pronunciation in MacOS X:

Sub Pronounce_active_cell()
    MacScript ("say " & """" & ActiveCell.Value & """")
End Sub
1
  • Thank you, Vadim! Works perfectly. (Note: this approach works only for reading whatever is set as the system language: if you want Excel to read French properly, your Mac must be set so that all the menus, dialog boxes and so on are in French.) Apr 29, 2017 at 18:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .