Forum Discussion

mctribeiro's avatar
mctribeiro
Copper Contributor
Sep 04, 2019
Solved

Setting IF function to speak a sentence

 

Hi everyone. I am trying, with no success, set an IF command, through VBA, to speak a pre set sentence if a pre defined condition is reached.

Example: =IF("A1>100";"Congratulation!! You reached your goal!";"")

The only thing I know I must use "application.speech.speak" as one of the commands in this VBA macro but I do not know how to build this program.

 

19 Replies

  • mctribeiro You asked the same question on another forum and I answered it there. Please don't ask the same thing in different places. You are wasting people's time. 

     

    Did you try my suggestion in the other forum? https://stackoverflow.com/questions/57779266/how-to-create-a-if-command-via-vba-to-sound-a-sentence/57779456#57779456

     

    You never replied. If people take the time to solve your problems, it would be great to give them some feedback. Happy to help if you need more assistance, but you have to communicate.

     

    • mctribeiro's avatar
      mctribeiro
      Copper Contributor
      Hello.
      Please, try to not be so rude in your comments. If you believe I am wasting your time simply ignore my question. It is very easy to judge people's actions and choices. And also remember: don't judge to avoid being judged. I hope you be well. Regards.
      • mctribeiro Sorry, but I didn't mean to be rude and I don't think I was. If you post the same question in different forums, somebody will work on your problem while someone else has already solved it. So that is indeed wasting people's time.  Maybe you want to read this:

         

        https://www.excelguru.ca/content.php?184

         

        It explains things better that I did. 

  • mctribeiro 

    Does A1 contain any formula which gets calculated based on other cells?

    If yes, you can use the Calculate Event to speak the predefined text. To do so, right click on Sheet Tab --> View code --> and paste the code given below into the opened code window.

     

    Private Sub Worksheet_Calculate()
    If Range("A1").Value > 100 Then
        Application.Speech.Speak "Congratulation!! You reached your goal!"
    End If
    End Sub

     

    If you manually change the cell A1, replace the above code with the Change Event code...

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Address(0, 0) = "A1" Then
        If Target > 100 Then
            Application.Speech.Speak "Congratulation!! You reached your goal!", True
        End If
    End If
    End Sub

    The attached contains two sheets named "Calculate Event" and "Change Event" for you test the above codes.

     

    If this is not what you are trying to achieve, please upload a sample workbook and explain that how do you want it to work.

     

     

    • mctribeiro's avatar
      mctribeiro
      Copper Contributor

      Subodh_Tiwari_sktneerHi my friend. I tested your program this morning and it worked almost perfectly. The only problem was the voice started a loop and did not stop at all. I had to shut Excell (not only the specific sheet) to definitely quit the voice. I am attaching the sheet which will receive the voice command. I highlighted in yellow the column with the cells that will "produce" the voice. Please, let me know if I did something wrong. My best regards,

      Marcelo

    • mctribeiro's avatar
      mctribeiro
      Copper Contributor
      Hello my friend.
      Thanks a lot for your quick response. The A1 cell is a result of other cells caculation, as your first assumption. I will test your command through your sheet example tomorrow and let you know the result. Thank you very much one more time.

Resources