Macro Linking to File name Based on a Cell Contents

dusty9

New Member
Joined
Oct 2, 2014
Messages
15
Office Version
  1. 2016
Platform
  1. Windows
Hi, I'm trying to run a macro which plays a song that has the file name the same as my cell x4 contents. I found a macro to play a song if it is a constant hyperlink, but I can't get it to change the file name depending on my x4 cell.
Here is what I tried; where I put & Range("X4").value & is where I want the file name to have the X4 cell value.

FileToPlay = """C:\Users\Dusty\Desktop\New Folder\ & Range("X4").value &.mp3"""
Shell "C:\Program Files\Windows Media Player\wmplayer /play /close " & FileToPlay

Any help would be appreciated
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Code:
[COLOR=#333333]FileToPlay = ""C:\Users\Dusty\Desktop\New Folder\" [/COLOR][B]& Range("X4").value & ".mp3""[/B]
 
Upvote 0
Thanks for the reply, looks like I might have just had quotations in the wrong spot but when I put in the line you posted, I get a Compile Error: Syntax Error
Am I still doing something wrong?

FileToPlay = ""C:\Users\Dusty\Desktop\New Folder\" & Range("X4").value & ".mp3""
Shell "C:\Program Files\Windows Media Player\wmplayer /play /close " & FileToPlay
 
Upvote 0

Forum statistics

Threads
1,215,159
Messages
6,123,348
Members
449,097
Latest member
thnirmitha

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