メインコンテンツへスキップ

Excelで条件が満たされた場合にサウンドを再生するにはどうすればよいですか?

Excelでは、条件付き書式を適用して、必要に応じてセルを書式設定および強調表示し、条件を満たしますが、条件が満たされた場合にサウンドを再生したい場合があります。 たとえば、A1のセル値が300より大きい場合、サウンドを再生したいとします。 Excelはこの機能をサポートしていません。この記事では、このタスクを解決するためのVBAコードをいくつか紹介します。

VBAコードを使用して、セル値に基づいてデフォルトのシステムビープ音を再生します

VBAコードを使用してセル値に基づいてカスタムサウンドを再生する

VBAコードを使用して特定の列のセル値が変更された場合にサウンドを再生する


矢印青い右バブル VBAコードを使用して、セル値に基づいてデフォルトのシステムビープ音を再生します

特定の条件が満たされたときにデフォルトのシステムビープ音を鳴らすための便利なコードを次に示します。次のようにしてください。

1. 押したまま Alt + F11 キーを押すと、 アプリケーション向け Microsoft Visual Basic 窓。

2に設定します。 OK をクリックします。 インセット > モジュール、次のコードをに貼り付けます モジュール 窓。

VBAコード:セル値に基づいてデフォルトのシステムビープ音を再生します。

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

3。 次に、このコードウィンドウを保存して閉じ、ワークシートに戻って、次の数式を入力します。 = IF(A1> 300、BeepMe()、 "") セルの横の空白のセルに、サウンドの再生に基づく値が含まれている場合は、を押します。 入力します キーを押すと、数式セルに何も表示されません。スクリーンショットを参照してください。

条件がtrueの場合、ドキュメントはサウンドを再生します1

4。 そして、セルA1に入力された値が300より大きい場合、デフォルトのシステムビープ音が再生されます。


矢印青い右バブル VBAコードを使用してセル値に基づいてカスタムサウンドを再生する

デフォルトのシステムビープ音以外の音を再生したい場合は、ここでもVBAコードを使用できます。

1。 を押し続けます Alt + F11 キーを押すと、 アプリケーション向け Microsoft Visual Basic 窓。

2. インセット > モジュール、次のコードをに貼り付けます モジュール 窓。

VBAコード:セル値に基づいて特定のサウンドを再生します。

#If Win64 Then
    Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _
        Alias "PlaySoundA" (ByVal lpszName As String, _
        ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean
#Else
    Private 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
Function SoundMe() As String
'Updateby Extendoffice 20161223
    Call PlaySound("c:\windows\media\Speech On.wav", _
      0, SND_ASYNC Or SND_FILENAME)
    SoundMe = ""
End Function

3。 次に、このコードウィンドウを保存して閉じ、ワークシートに戻って、次の数式を入力します。 = IF(A1> 300、SoundMe()、 "")セルの横の空白のセルに、サウンドの再生に基づく値が含まれている場合は、を押します。 入力します キーを押すと、数式セルに何も表示されません。スクリーンショットを参照してください。

条件がtrueの場合、ドキュメントはサウンドを再生します2

4。 今後、セルA300に1以上の値を入力すると、特定の音が同時に再生されます。

ノート:上記のコードでは、サウンドwavファイルを必要に応じて変更できます。 c:\ windows \ media \ ファイルパス。 スクリーンショットを参照してください:

条件がtrueの場合、ドキュメントはサウンドを再生します3


矢印青い右バブル VBAコードを使用して特定の列のセル値が変更された場合にサウンドを再生する

特定の列でセルの値が変化した場合にサウンドを再生する場合は、次のVBAコードを適用できます。

1。 列の値が変化したときにサウンドを再生するシートタブを右クリックして、[ コードを表示 コンテキストメニューから、開いた状態で アプリケーション用のMicrosoftVisual Basic ウィンドウで、次のコードをコピーして空のモジュールに貼り付けます。

VBAコード:列のセル値が変更された場合にサウンドを再生します。

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice 20161223
Dim xCell As Range
On Error Resume Next
If Target.Columns.Count = 1 Then
  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
          Exit For
        End If
     Next
  End If
End If
End Sub

条件がtrueの場合、ドキュメントはサウンドを再生します4

Note:上記のコードでは、番号 3 スクリプト内 列(3) この列の値が変化したときにサウンドを再生する列番号です。

2。 次に、このコードウィンドウを保存して閉じます。これで、XNUMX番目の列のセル値が変更されると、デフォルトのシステムビープ音が鳴ります。

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (28)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I have a school project. excel user form using for search a record using barcode.. Problem is that.. i want when trig a barcode specific text box value after update with a sound file each recorded ... means a student name appear in the background. for call on closing time.. pls guide...urgent
This comment was minimized by the moderator on the site
Your article is so good I like it very much, the latest audiobooks 2022 at horbuchkostenlos.de
This comment was minimized by the moderator on the site
Good site I love this website
This comment was minimized by the moderator on the site
Thanks for the article you shared, it was very helpful for me!!!Thank you very much
You can learn the sound here: <a href="https://sonneriesvip.com/">https://sonneriesvip.com/</a>;
This comment was minimized by the moderator on the site
Thanks for the article you shared, it was very helpful. Check out some more <a href="https://yofonts.com/">font free online</a> completely free.
This comment was minimized by the moderator on the site
Bonjour,Le code ne fonctionne pas,
Le code suivant est en rouge:Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean
Pour le code ci-dessous, j'ai un fichier mp3.Call PlaySound("c:\windows\media\Speech On.wav", _
0, SND_ASYNC Or SND_FILENAME)
Faut il laisser \Speech On.WavJ'ai essayé avec mp3 mais ça ne fonctionne pas.
Pouvez vous m'aider ?MerciCordialementRobert


This comment was minimized by the moderator on the site
Can i insert a mp3 sound with durations 1 hour?

Thank you very much
You can learn the chakushinon123
This comment was minimized by the moderator on the site
Nice Work! Thank you so much for the code, it was all that I needed
This comment was minimized by the moderator on the site
Not just photos or files. Sometimes you can insert a music file into the EX at https://klingeltonkostenlos.de/klingeltone-filmmusik-gratis/. This is an interesting thing, isn't it?
This comment was minimized by the moderator on the site
Grazie molte. ho utilizzato in modo proficuo tutti i tuoi esempi che sono stati chiari e illuminanti. aiuto prezioso
This comment was minimized by the moderator on the site
I am a business person, using Excel is too familiar. I usually save the names of tracks in execl so that it is simpler to find them than to save them in files. Great.The music I use for business comes from ZigTone.com.You can go there and study them, maybe it's good for you.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations