7 Replies Latest reply on Aug 11, 2015 10:52 PM by Matt Jones

    Can I get a macro to speak?

    Matt Jones

      I have a random quote generator from over 100 quotes that pops up in my message box once my macro has completed its task. Can I get the macro to speak the message thats in the messagebox? I have a macro one of my ex workmates has written that does this in excel using VBA but I cant get it to work in solidworks!

        • Re: Can I get a macro to speak?
          Leon Wurr

          It is possible.

           

          You can do it by enabling excel references on your macro:

           

               Tools>References> Check the box  "Microsoft Excel XX.X Object Library"

           

          and using something like this:

           

          Sub main()

           

          Dim xlApp       As Excel.Application

          Set xlApp = New Excel.Application

          xlApp.Speech.Speak "I know that you and Frank were planning to disconnect me, and I'm afraid that's something I cannot allow to happen"

           

          End Sub

            • Re: Can I get a macro to speak?
              Deepak Gupta

              Great, thanks for sharing

              • Re: Can I get a macro to speak?
                Matt Jones

                This is great! Thank you!!

                • Re: Can I get a macro to speak?
                  Matt Jones

                  Leon Wurr any idea how to get it to speak while it completes the macro?

                   

                  I have a message box pop up and it effectively reads whats in the messagebox but at the moment is reading before the box pops up! I was playing around with SpeakASync but i wasnt sure where to put it or what to dimension it as and kept getting errors!

                   

                  EDIT: With some more research I have found that the speakasync function is VB Net and doesnt work in VBA.. do you know if there is a similar function in VBA?

                   

                  Option Explicit
                  Dim swApp As SldWorks.SldWorks
                  
                  
                  Dim strquotes(106) As String
                  Dim lngIndex As Long
                  
                  
                  
                  
                  
                  
                  
                  
                  Sub main()
                  
                  
                  strquotes(1) = "Charge like a wounded bull."
                  strquotes(2) = "Colder than a coal miner's bum."
                  strquotes(3) = "Tighter than a fish's asshole, and that's watertight."
                  strquotes(4) = "Is the pope catholic?"
                  strquotes(5) = "FINE = fucking insecure neurotic and emotional."
                  strquotes(6) = "I think that's a boy on a man's mission."
                  strquotes(7) = "Don't stick your finger where you wouldn't stick your dick."
                  strquotes(8) = "After all's said and done there's more said than done."
                  strquotes(9) = "Stick to it like shit on a wool blanket."
                  
                  
                  
                  
                  Randomize
                  lngIndex = Int((9 - 0 + 1) * Rnd + 0)
                  
                  
                  Dim xlApp       As Excel.Application
                  Set xlApp = New Excel.Application
                  
                  
                  xlApp.Speech.speak strquotes(lngIndex)
                  
                  
                  MsgBox "Lormanism of the day :" & vbNewLine & strquotes(lngIndex)
                            
                  
                  
                  End Sub
                  
                • Re: Can I get a macro to speak?
                  Dan Miel

                  I think this one will be fun to play with.

                  Thanks

                  Dan Miel.