How to create my own "text to speech" in vba

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I would like to make my own "text to speech" in vba, when the user kept the mouse over a button or a textbox I would like the program to play a specific audio created by me, how can I do this?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
The following will speak the word/s that are highlighted :

VBA Code:
ption Explicit

#If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
#End If

Sub SpeakCells()
Dim rRange As Range
Dim rCell As Range

Set rRange = Selection

For Each rCell In rRange
Application.Speech.Speak rCell.Text, Purge:=True, SpeakAsync:=True
Sleep 1000 'wait 1000 milliseconds (1 second)
Next rCell

End Sub

You can combine the above macro to be run with another macro that recognizes 'hovering' over a cell or text box. I would do a search for
"vba mouse hover run macro"
 
Upvote 0
The following will speak the word/s that are highlighted :

VBA Code:
ption Explicit

#If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
#End If

Sub SpeakCells()
Dim rRange As Range
Dim rCell As Range

Set rRange = Selection

For Each rCell In rRange
Application.Speech.Speak rCell.Text, Purge:=True, SpeakAsync:=True
Sleep 1000 'wait 1000 milliseconds (1 second)
Next rCell

End Sub

You can combine the above macro to be run with another macro that recognizes 'hovering' over a cell or text box. I would do a search for
"vba mouse hover run macro"
but is it possible to put a specific audio file for him to speak when the mouse is over?
 
Upvote 0
Depends on what it is you are attempting to achieve. If you are anticipating 6 or 10 different cells that the mouse will hover over, and the response for reading the text therein will always be the same, you could use a SELECT CASE statement for each cell or IF statements referring to each cell location.

If you are desiring the 'computer reading text' to happen no matter which cell the mouse hovers over (every cell in the workbook) ... that is going to require a substantial amount of coding. Probably more than Excel is truly capable of accomplishing.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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