VBA to play sound from file location after macro is done

kenchristensen11

Board Regular
Joined
Oct 12, 2016
Messages
52
Hello,

I have the below code and after the macro is completed (e.g., after the "Archive" button is clicked and the macro runs), I would to play an .mp3 file from file location, but I haven't had any luck.

Is there any way this can be done? Thanks!!

VBA Code:
Sub FileAway()
 Dim PssWrd
 Dim sourceSheet As Worksheet
 Dim targetSheet As Worksheet
 Dim lastRow As Long
 Dim i As Long

    
    PssWrd = Application.InputBox(Prompt:="Are you Tim or Kevin?")
    
    If PssWrd <> "RESIDUALS" Then
         Exit Sub
    Else
 
' Set the source and target sheets
Set sourceSheet = ThisWorkbook.Worksheets("All Quarters")
Set targetSheet = ThisWorkbook.Worksheets("Archive")

' Find the last row in the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "B").End(xlUp).Row

' Loop through each row in the source sheet
For i = 9 To lastRow
' Check if cell in column B contains "Archive"
If sourceSheet.Cells(i, "B").Value = "Archive" Then
' Copy the entire row to the target sheet
sourceSheet.Rows(i).Copy Destination:=targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Offset(1)
' Delete the row from the source sheet
sourceSheet.Rows(i).Delete
' Decrement the loop counter as the rows are shifting up
i = i - 1
' Update the last row value
lastRow = lastRow - 1
End If
Next i
    End If
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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