This is a macro to demonstrate text to speech capabilities. A userForm pops up asking for text. The user types in any text and the user's computer will read the text aloud. Pressing enter triggers the text to speech subroutine and then the userForm is cleared. There are more simple macros on the SolidWorks Macros page.

Audio2.bmp
Audio2.swp

  1.  
  2. Dim speaks, speech
  3.  
  4. Sub main()
  5. UserForm1.Show
  6. End Sub
  7.  
  8. Sub sayThis(sp As String)
  9. Set speech = CreateObject("sapi.spvoice")
  10. speech.Speak sp
  11. End Sub
  12.  

      Below is the userForm code. I set this macro up so you can continuously enter text and run the text to speech subroutine every time the enter button is pressed. The userForm is basically listening for the enter button to be pressed before triggering the text to speech subroutine and then clearing out the userForm's text. Pressing the Exit button ends the macro with one line of code. There are more simple macros on the SolidWorks Macros page.

  1.  
  2. Private Sub CommandButton1_Click()
  3. End
  4. End Sub
  5.  
  6. Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  7. If KeyCode = 13 Then
  8. KeyCode = 0 'this line keeps the focus from shifting away from Textbox1'
  9. speaks = TextBox1.Text
  10. TextBox1.Text = ""
  11. sayThis (speaks)
  12. End If
  13. End Sub
  14.