macro to play a vba file

glad_ir

Board Regular
Joined
Nov 22, 2020
Messages
143
Office Version
  1. 2010
Platform
  1. Windows
Hello,

Please can somebody advise what code I should use to play a .wav file stored on my C drive when a shape is selected/clicked on?

Thank you,
Iain
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try this (obviously changing the full path to where the file resides first):

VBA Code:
CreateObject("Shell.Application").ShellExecute "C:\Users\Iain\Song Title.wav"

Regards,

Robert
 
Upvote 0
Solution
Try this (obviously changing the full path to where the file resides first):

VBA Code:
CreateObject("Shell.Application").ShellExecute "C:\Users\Iain\Song Title.wav"

Regards,

Robert
Hi Robert, apologies for my slow response - this is perfect. Thank you.

One follow on question if I may......is there a way to play the wav file without it opening in front of the excel sheet?

thanks!
Iain
 
Upvote 0
Hi Iain,

I'm sure there's a way but I'm not sure to be honest. You can use this that hides the file...

VBA Code:
Option Explicit
Sub Macro1()

    Dim objWSH As Object

    Set objWSH = CreateObject("WScript.Shell")
    
    objWSH.Run ("""C:\Users\Iain\Song Title.wav"""), 0 '0 = Hide the file

    Set objWSH = Nothing

End Sub

...but to minimize the file you can try the Application.FollowHyperlink method but that produces a series of alerts that I believe can only be turned off via editing the registry (refer here).

Maybe someone on the forum will have a solution.

Regards,

Robert
 
Upvote 0
Hi Iain,

I'm sure there's a way but I'm not sure to be honest. You can use this that hides the file...

VBA Code:
Option Explicit
Sub Macro1()

    Dim objWSH As Object

    Set objWSH = CreateObject("WScript.Shell")
   
    objWSH.Run ("""C:\Users\Iain\Song Title.wav"""), 0 '0 = Hide the file

    Set objWSH = Nothing

End Sub

...but to minimize the file you can try the Application.FollowHyperlink method but that produces a series of alerts that I believe can only be turned off via editing the registry (refer here).

Maybe someone on the forum will have a solution.

Regards,

Robert
Thank you for your help Robert - much appreciated!

Best regards,
Iain
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,272
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top