Sidor om ämnet: [1 2] > | Visual Basic Macro: Can someone debug it? Trådens avsändare: Patricia Rosas
| Patricia Rosas USA Local time: 09:47 Spanska till Engelska + ... In memoriam
The other day, I asked for help to get the text-to-speech feature running in Word 2007. Andy Tolle gave me a macro, that I've found out on the Internet at this address, too:
http://www.gmayor.com/word_text_to_speech.htm
(the macro itself appears toward the bottom of the page).
Everything works great for the "Speak Text" button, but I cannot get the "Stop Speaking" ... See more The other day, I asked for help to get the text-to-speech feature running in Word 2007. Andy Tolle gave me a macro, that I've found out on the Internet at this address, too:
http://www.gmayor.com/word_text_to_speech.htm
(the macro itself appears toward the bottom of the page).
Everything works great for the "Speak Text" button, but I cannot get the "Stop Speaking" button to work. I've never worked with VB, and I'm wondering if there is an error in this part of the macro. I'm hoping that someone familiar with VB might be able to spot it (or tell me how to get the debugger to work, because I'm not getting error messages):
Sub StopSpeaking()
'Based on a macro by Mathew Heikkila
'used to interrupt any running speech to text
On Error Resume Next
speech.Speak vbNullString, SVSFPurgeBeforeSpeak
Set speech = Nothing
End Sub
Any light that can be shed on this problem will be greatly appreciated!
Patricia ▲ Collapse | | | Daniel Grau Argentina Medlem (2008) Engelska till Spanska | speech is probably undefined | Jul 30, 2009 |
As Daniel already said, "speech" is probably undefined in this context.
To get the debugger to work, you need to disable the line "On Error Resume Next".
HTH,
Benjamin | | | Patricia Rosas USA Local time: 09:47 Spanska till Engelska + ... TOPIC STARTER In memoriam where or how? | Jul 30, 2009 |
Daniel,
I looked at the code for "taking a break" but I'm so new to this that I don't understand what you mean by "defining speech outside the subroutines." The full routine that I'm running is this (and I think the very first line is what you are talking about, right?):
Dim speech as SpVoice 'Don't overlook this line!
Sub SpeakText()
'Based on a macro by Mathew Heikkila
'
On Error Resume Next
Set speech = New SpVoice
... See more Daniel,
I looked at the code for "taking a break" but I'm so new to this that I don't understand what you mean by "defining speech outside the subroutines." The full routine that I'm running is this (and I think the very first line is what you are talking about, right?):
Dim speech as SpVoice 'Don't overlook this line!
Sub SpeakText()
'Based on a macro by Mathew Heikkila
'
On Error Resume Next
Set speech = New SpVoice
If Len(Selection.Text) > 1 Then 'speak selection
speech.Speak Selection.Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
Else 'speak whole document
speech.Speak ActiveDocument.Range(0, ActiveDocument.Characters.Count).Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
End If
Do
DoEvents
Loop Until speech.WaitUntilDone(10)
Set speech = Nothing
End Sub
Sub StopSpeaking()
'Based on a macro by Mathew Heikkila
'used to interrupt any running speech to text
On Error Resume Next
speech.Speak vbNullString, SVSFPurgeBeforeSpeak
Set speech = Nothing
End Sub
Thanks,
Patricia ▲ Collapse | |
|
|
Terry Richards Frankrike Local time: 18:47 Franska till Engelska + ...
Before I start, I'm not that familiar with VB and I know nothing about the SpVoice object. But, I have been programming professionally for over 30 years...
It looks to me like your text has got split up (probably so it fits into tye line length of a book?). The two lines ending in an underscore should be unwrapped (delete the underscore and the new line so the following line flows up). If these lines are being treated as separate statements, the async parameter is not being passed t... See more Before I start, I'm not that familiar with VB and I know nothing about the SpVoice object. But, I have been programming professionally for over 30 years...
It looks to me like your text has got split up (probably so it fits into tye line length of a book?). The two lines ending in an underscore should be unwrapped (delete the underscore and the new line so the following line flows up). If these lines are being treated as separate statements, the async parameter is not being passed to the SpVoice object which (I guess) means that it is running synchronously - i.e. it is not yielding to the message queue and your second routine isn't getting triggered until the first one has finished.
If this is the case, deleting the underscores and line ends will fix it. If not, deleting them will do no harm.
You could also put a message box at the beginning of StopSpeaking to see if it is getting called at all and, if so, when it is getting called. Does the message appear while it is still speaking or does it appear after speaking has finished or does it not appear at all?
Terry. ▲ Collapse | | |
A search for "as spvoice" gives several interesting results, one of which leads to this illustrated guide:
http://www.gmayor.com/word_text_to_speech.htm
HTH,
Benjamin
P.S.: The underscore is what allows the wrapped code to still work (by VB conventions). But yes, you can delete it and put the contents of the 2nd line on the first line and it'll wo... See more A search for "as spvoice" gives several interesting results, one of which leads to this illustrated guide:
http://www.gmayor.com/word_text_to_speech.htm
HTH,
Benjamin
P.S.: The underscore is what allows the wrapped code to still work (by VB conventions). But yes, you can delete it and put the contents of the 2nd line on the first line and it'll work just as well.
[Edited at 2009-07-30 19:12 GMT] ▲ Collapse | | | Jaroslaw Michalak Polen Local time: 18:47 Medlem (2004) Engelska till Polska SITE LOCALIZER Declarations | Jul 30, 2009 |
Benjamin is right, underscores allow to split the lines in the source, so it is not a problem...
The issue, I think, is that the line:
Dim speech as SpVoice 'Don't overlook this line!
has to be at the very start of the module, not the procedure... Module is the whole text block you see in the editor, most probably it is called "NewMacros" (you can see all the modules in the tree on the left).
If you have any other user macros, it might b... See more Benjamin is right, underscores allow to split the lines in the source, so it is not a problem...
The issue, I think, is that the line:
Dim speech as SpVoice 'Don't overlook this line!
has to be at the very start of the module, not the procedure... Module is the whole text block you see in the editor, most probably it is called "NewMacros" (you can see all the modules in the tree on the left).
If you have any other user macros, it might be that the line got attached to them, like this:
Code:
|
Sub Someothermacro()
...
End sub
Dim speech as SpVoice 'Don't overlook this line!
Sub SpeakText()
|
|
What you have to do is to move the line to the very start of the whole module. You will know if it is correct, when the cursor placed on the line will change the text of the combo boxes at the top from (General) SomeOtherMacro to (General)(Declarations).
Of course, you can also put the macros into another module, but this is slightly more complicated... ▲ Collapse | | | Terry Richards Frankrike Local time: 18:47 Franska till Engelska + ... Continuation character | Jul 31, 2009 |
So the underscore is a VB continuation character. I didn't know that. In that case, the first part of my answer is nonsense
However, the bit about the message box is still useful. It will tell you if the subroutine is being called at all and, if it is, when it is being called.
T. | |
|
|
Patricia Rosas USA Local time: 09:47 Spanska till Engelska + ... TOPIC STARTER In memoriam that was the page I copied | Jul 31, 2009 |
Actually, this link is the one I copied the code from. But thanks for sharing it. | | | Patricia Rosas USA Local time: 09:47 Spanska till Engelska + ... TOPIC STARTER In memoriam I'm trying to follow ... | Jul 31, 2009 |
Jabberwock wrote:
What you have to do is to move the line to the very start of the whole module. You will know if it is correct, when the cursor placed on the line will change the text of the combo boxes at the top from (General) SomeOtherMacro to (General)(Declarations).
Of course, you can also put the macros into another module, but this is slightly more complicated...
Sorry, I'm being such a dunce, but as far as I can tell, the line is at the very beginning:
Sub TextToSpeech()
Dim speech As SpVoice
End Sub
***HERE A GREY LINE APPEARS ACROSS THE SCREEN***
Sub SpeakText()
'Based on a macro by Mathew Heikkila
But when I place the cursor on the first line, the combo boxes read "General" and it switches to "TextToSpeech," the name of the macro. It should read "Declarations"? Do you think that somehow the Sub TextToSpeech() isn't really at the top, even though it appears to be?
Thanks again, everyone! | | | Patricia Rosas USA Local time: 09:47 Spanska till Engelska + ... TOPIC STARTER In memoriam tried again and still no luck | Jul 31, 2009 |
I realized that there was a blank line before the Sub TextToSpeech line, so I removed it, and when I put the cursor on the phrase, the box read "Declarations." I saved everything, removed the old macro buttons from the ribbon, and reinstalled the new version.
But the Stop Speaking subroutine still doesn't work.
When I returned to VB, the module had changed and the first line was highlighted in yellow with an arrow, and the box again said "TextToSpeech"...
... See more I realized that there was a blank line before the Sub TextToSpeech line, so I removed it, and when I put the cursor on the phrase, the box read "Declarations." I saved everything, removed the old macro buttons from the ribbon, and reinstalled the new version.
But the Stop Speaking subroutine still doesn't work.
When I returned to VB, the module had changed and the first line was highlighted in yellow with an arrow, and the box again said "TextToSpeech"...
Any other ideas?? ▲ Collapse | | | Jaroslaw Michalak Polen Local time: 18:47 Medlem (2004) Engelska till Polska SITE LOCALIZER Before the Sub... | Jul 31, 2009 |
The Dim line is supposed to be the first line of the module, i.e. it should come before the very first Sub command.
Try removing the TexttoSpeech() macro (it is not supposed to be there anyway)... Move the cursor all the way up, put the Dim line (it should indicate Declarations) there and only then you can have the first Sub...
I hope this is clear enough... If you do not have any other macros defined (and from your description it seems that you don't), ju... See more The Dim line is supposed to be the first line of the module, i.e. it should come before the very first Sub command.
Try removing the TexttoSpeech() macro (it is not supposed to be there anyway)... Move the cursor all the way up, put the Dim line (it should indicate Declarations) there and only then you can have the first Sub...
I hope this is clear enough... If you do not have any other macros defined (and from your description it seems that you don't), just open the Editor, delete everything from the window and paste the code exactly as it appears on the linked page (i.e. starting with the Dim line).
[Edited at 2009-07-31 19:25 GMT] ▲ Collapse | |
|
|
Patricia Rosas USA Local time: 09:47 Spanska till Engelska + ... TOPIC STARTER In memoriam screen shot below . . . | Jul 31, 2009 |
I did what you suggested, and stop speaking macro still won't work; here's a screen shot from the module:
Dim speech as SpVoice 'Don't overlook this line!
Sub SpeakText()
'Based on a macro by Mathew Heikkila
'
On Error Resume Next
Set speech = New SpVoice
If Len(Selection.Text) > 1 Then 'speak selection
speech.Speak Selection.Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
Else 'speak whole document
... See more I did what you suggested, and stop speaking macro still won't work; here's a screen shot from the module:
Dim speech as SpVoice 'Don't overlook this line!
Sub SpeakText()
'Based on a macro by Mathew Heikkila
'
On Error Resume Next
Set speech = New SpVoice
If Len(Selection.Text) > 1 Then 'speak selection
speech.Speak Selection.Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
Else 'speak whole document
speech.Speak ActiveDocument.Range(0, ActiveDocument.Characters.Count).Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
End If
Do
DoEvents
Loop Until speech.WaitUntilDone(10)
Set speech = Nothing
End Sub
Sub StopSpeaking()
'Based on a macro by Mathew Heikkila
'used to interrupt any running speech to text
On Error Resume Next
speech.Speak vbNullString, SVSFPurgeBeforeSpeak
Set speech = Nothing
End Sub
Between each End Sub and Sub and after the Dim Speech line, there is a pale grey line. I save everything in Normal, dump the old icons, reinsert the new ones on the ribbon, but it still doesn't work. Also, the cursor on the Dim line makes the box read declarations ... ▲ Collapse | | | Jaroslaw Michalak Polen Local time: 18:47 Medlem (2004) Engelska till Polska SITE LOCALIZER
In that case I do not know why it fails, it works in my case...
You should comment out (put the apostrophe) the line
On Error Resume Next
in the StopSpeaking procedure - then you will know what is the error code...
Alternately, you may press Ctrl+Pause/Break key, this will stop the macro execution, but is less convenient, of course. | | | Patricia Rosas USA Local time: 09:47 Spanska till Engelska + ... TOPIC STARTER In memoriam where is the pause key? | Jul 31, 2009 |
Dear Jabberwock,
I've been deeply grateful for your help. I tried the commenting out step, but the text did not turn green. Does that matter?
Can you tell me where the pause/break key is on a keyboard?
Thanks again,
Patricia | | | Sidor om ämnet: [1 2] > | To report site rules violations or get help, contact a site moderator: You can also contact site staff by submitting a support request » Visual Basic Macro: Can someone debug it? Wordfast Pro |
---|
Translation Memory Software for Any Platform
Exclusive discount for ProZ.com users!
Save over 13% when purchasing Wordfast Pro through ProZ.com. Wordfast is the world's #1 provider of platform-independent Translation Memory software. Consistently ranked the most user-friendly and highest value
Buy now! » |
| Trados Business Manager Lite |
---|
Create customer quotes and invoices from within Trados Studio
Trados Business Manager Lite helps to simplify and speed up some of the daily tasks, such as invoicing and reporting, associated with running your freelance translation business.
More info » |
|
| | | | X Sign in to your ProZ.com account... | | | | | |