banner



How To Play Mp3 File In Background With Vba In Windows

How to play a sound if a condition is met in Excel?

In Excel, we tin can utilise the Conditional Formatting to format and highlight the cells to run across the condition equally you need, but, sometimes, yous may want to play a audio if a condition is met. For case, if cell value in A1 is greater than 300, I desire a sound is played. Excel does non support this characteristic, this article, I will introduce some VBA codes to solve this chore.

Play a default organisation beep audio based on cell value with VBA code

Play a custom audio based on cell value with VBA code

Play a sound if cell value changes in a specific column with VBA code


arrow blue right bubble Play a default organization beep sound based on cell value with VBA code

Here is a handy code for you to play a default system beep sound when a specific condition is met, delight do as this:

one. Hold down the ALT + F11 keys, so it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Play a default system beep audio based on a cell value:

          Role BeepMe() As String     Beep     BeepMe = "" End Function                  

3. Then salvage and close this code window, go back to the worksheet, and enter this formula: =IF(A1>300,BeepMe(),"") into a blank cell beside the prison cell contains the value yous want to play a audio based on, so press Enter primal, nothing will be displayed into the formula cell, see screenshot:

doc play sound if conditon true 1

four. And now, if the entered value in cell A1 is greater than 300, a default organization beep sound will be played.


arrow blue right bubble Play a custom sound based on cell value with VBA code

If you want to play another audio than the default system beep sound, here also a VBA lawmaking tin can practice you lot a favor.

i. Concur downwards the ALT + F11 keys, then information technology opens the Microsoft Visual Basic for Applications window.

two. Click Insert > Module, and paste the following lawmaking in the Module Window.

VBA code: Play a specific sound based on a cell value:

          #If Win64 Then     Individual Declare PtrSafe Office PlaySound Lib "winmm.dll" _         Allonym "PlaySoundA" (ByVal lpszName Every bit String, _         ByVal hModule As LongPtr, ByVal dwFlags Equally Long) As Boolean #Else     Individual Declare Function PlaySound Lib "winmm.dll" _         Alias "PlaySoundA" (ByVal lpszName As String, _         ByVal hModule As Long, ByVal dwFlags As Long) As Boolean #End If Const SND_SYNC = &H0 Const SND_ASYNC = &H1 Const SND_FILENAME = &H20000 Part SoundMe() As String 'Updateby Extendoffice 20161223     Call PlaySound("c:\windows\media\Speech On.wav", _       0, SND_ASYNC Or SND_FILENAME)     SoundMe = "" End Function                  

iii. Then save and close this code window, return to the worksheet, and enter this formula: =IF(A1>300,SoundMe(),"") into a blank cell beside the cell contains the value you want to play a audio based on, and so press Enter central, naught will exist displayed into the formula cell, see screenshot:

doc play sound if conditon true 2

4. From now on, if a value greater than 300 is entered into prison cell A1, a specific sound will be played at one time.

Notes: In the above lawmaking, y'all tin change the sound wav file to your need from c:\windows\media\ file path. See screenshot:

doc play sound if conditon true 3


arrow blue right bubble Play a sound if cell value changes in a specific column with VBA code

If you want to play a sound if jail cell value changes in a specific column, you can apply the following VBA code.

1. Correct click the canvass tab that you want to play a sound when value changes in a column, so cull View Code from the context menu, and in the opened Microsoft Visual Basic for applications window, re-create and paste the following code into the blank Module:

VBA code: Play a sound if cell value changes in a cavalcade:

          Private Sub Worksheet_Change(ByVal Target Every bit Range) 'Updateby Extendoffice 20161223 Dim xCell Every bit Range On Mistake Resume Next If Target.Columns.Count = 1 And so   If Intersect(Target, Columns(3)) Is Nothing Then     Exit Sub   Else     For Each xCell In Columns(3)         On Error Resume Next         If (xCell.Value = Target.Value) And (xCell.Value <> "") Then           Beep           Leave For         End If      Adjacent   End If Terminate If End Sub                  

doc play sound if conditon true 4

Annotation: In the above code, the number iii in the script Columns(3) is the column number which you desire to play sound when value changes in this column.

2. And so save and close this code window, now, if a prison cell value changes in the third column, a default system beep sound will be played.


The Best Part Productivity Tools

Kutools for Excel Solves Nearly of Your Issues, and Increases Your Productivity by lxxx%

  • Reuse: Quickly insert complex formulas, charts  and anything that yous have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Information; Split Cells Content; Combine Duplicate Rows/Columns... Foreclose Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Notice and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Machine Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove past Position, Remove Space; Create and Impress Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (salve and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by assuming, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Information into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Piece of cake deploying in your enterprise or arrangement. Full features 30-day free trial. lx-day money dorsum guarantee.

kte tab 201905


Office Tab Brings Tabbed interface to Office, and Make Your Piece of work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint , Publisher, Access, Visio and Project.
  • Open up and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for y'all every 24-hour interval!

officetab bottom

How To Play Mp3 File In Background With Vba In Windows,

Source: https://www.extendoffice.com/documents/excel/4417-excel-play-sound-if-condition-is-true.html

Posted by: wrightsagessay.blogspot.com

0 Response to "How To Play Mp3 File In Background With Vba In Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel