• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

how to play a song with the starting of excel file? [SOLVED]

mahaveer

Member
i have a song in xyz folder of D Drive in .mp3 format how can i play this song automatically when my workbook open every time?
 
Put this code in 'ThisWorkbook' Module and test:

[pre]
Code:
Private Sub Workbook_Open()
'Put path of the song here
Const strSong As String = "D:xyzMySong.mp3"
Shell Environ$("ComSpec") & " /c " & Chr(34) & strSong & Chr(34), 0
End Sub
[/pre]
 
thanks shrivallabha


really its working when i open this workbook there automatically opens vlc player... actually when want that when i will open this workbook songs play but vlc player stay hide...only background music runs...is it possible?


Thanks again in advance

CA Mahaveer Somani
 
I tried few things but it fails to hide Winamp completely [goes off from taskbar]. I am not sure where does it go wrong or this procedure has bug. See if this works at your place.

[pre]
Code:
Private Sub Workbook_Open()
Const strPath As String = "C:Program FilesWinampwinamp.exe"  'Winamp path
Const strSong As String = "D:songs2 Jab Se Tere Naina.mp3"   'Put path of the song here
Shell strPath & " " & Chr(34) & strSong & Chr(34), 0
End Sub
[/pre]
 
hey thanks bro


its really working in background

but its really very very hard to me that how to shut down this song now....its continuously running...even i closed down the excel file too...


thanks in advance...dear
 
1. Start "Windows Task Manager" [Press CTRL + ALT + DEL keys all at a time]

2. Go to "Processes" Tab

3. You will find "winamp.exe" listed.

4. Right Click on it and choose "End Process" and you should be done.


Running winamp file is asynchronous task. We just invoke winamp as soon as we start our file but they are not related. So that is why closing the Excel file will not have any effect on the winamp.
 
@shrivallabha


Hi


it is a great code but there is one request for my side that is i got error from the last code


that is run time error 53, file is not found


when i press the debug then its shows the line is


Shell strPath & " " & Chr(34) & strSong & Chr(34), 0


kindly suggest while my system has 64 bit


Thanks


SP
 
@ mahaveer,


Please add reference to Microsoft Word Library as I have also commented in the code. Mine is 2007 (Office 12) so depending on the version of office your reference will change but the methodology will remain same.


Now when you will close this particular workbook, you'll get option to close winamp via a messagebox.


Replace code in 'ThisWorkbook' module with this code.

[pre]
Code:
Option Explicit
'Needs to set reference to MS Word VBA as shown below
'VBE | Tools | References | Microsoft Word 12.0 Object Library

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim vbMsgRes As VbMsgBoxResult
Dim tsk As Task
Dim wdApp As Word.Application

vbMsgRes = MsgBox("Do you want to close WinAmp also?", vbYesNo)

Select Case vbMsgRes

Case vbYes
'Create one instance of word which is hidden
Set wdApp = New Word.Application
wdApp.Visible = False

'Loop through all instances
For Each tsk In Tasks
If InStr(tsk.Name, "Winamp") > 0 Then
tsk.Close
End If
Next

wdApp.Quit

Case vbNo
'We do nothing if the input is no
End Select

End Sub

Private Sub Workbook_Open()
Const strPath As String = "C:Program FilesWinampwinamp.exe"  'Winamp path
Const strSong As String = "D:songs2 Jab Se Tere Naina.mp3"   'Put path of the song here
Shell strPath & " " & Chr(34) & strSong & Chr(34), 0
End Sub
[/pre]
----------------------------------------------------------------------------------------------------------------------------------------------------


@ sgmpatnaik,

No code is great if it doesn't work ;)


strPath needs to be checked and point to winamp.exe's path which may be different on your PC. Could you check it please?
 
@Shrivallaba


Hi


Yes you are right it's my mistake and it's working great


i have small doubt that is why we refer to MS Word Library to close the file


Thanks


SP
 
Hi SP,


When we do coding inside Excel, we are exposed to Excel's (Application) object model. Typical examples of such objects would be Workbook, Worksheet, Range etc. and the top most object is Application itself. These built-in objects have methods and properties that we can utilize to automate the activity at hand.


When we are looking at different applications such as Excel, Word, PowerPoint, they are developed by different development teams. So there would be some methods and functions that will be common to all applications and the rest will be application specific. Yet, we can use them in our application by referencing their component object model. This is done by setting appropriate reference in the Visual Basic Editor.


In above case, we are utilizing a useful object by the name "TASK" which is available under Word application (but there is no Excel equivalent of "TASK" object). That is reason why need to access Word's object library. So when we attach reference to 'Microsoft Word 12.0 Object Library' you will see that the underlying filename is MSWORD.OLB where OLB stands for Object Library. After this point it is simple matter of dimensioning variable like we do for other objects and using it in our code.


I hope this clarifies the need to refer MSWord Object library.
 
Hi,


I have a sort of similar question, so posting here.


Sorry if this is violating rules.


I have a file, I have inserted an .MP3 file in the excel file.


I want to play MP3 on opening the excel file.


The code in the original post will work if we give the file path.

Is it possible to play the inserted file.


I have also uploaded a sample workbook for the reference.


The inserted MP3 is Sheet2,


http://rapidshare.com/files/534795567/MyMusic.xlsb


Can anyone help me in this please.
 
Give this a shot.

[pre]
Code:
Option Explicit
Private Sub Workbook_Open()
Dim shp As Shape
Dim ws As Worksheet
Set ws = Worksheets("Sheet2")

On Error Resume Next
For Each shp In ws.Shapes
If shp.Title = "Package" Then
shp.OLEFormat.Verb
Exit For
End If
Next shp

End Sub
[/pre]
 
Back
Top