# Voice activation software to run macros?



## TedX (Dec 5, 2022)

One of the reasons I like creating macros to speed things along in Excel is that I'm lazy. I assume I am not alone in that department  🤪 

So my question is, is there any voice activation software around (even in Beta) that would let me say commands that would run macros?


----------



## MCLIFTO8 (Dec 6, 2022)

Yes. Yes you can!

*Talking to Excel and running a macro*
You can talk to excel using the _Microsoft Speech Object Library_
Wise owl has a nice tutorial on how to use it.

So what you do is set up the speech recognition event to a trigger, that might be a button, changing a cell, timer based. Anything. 

Then inside the speech recognition event you put a switch case statement in to select your macro based on what you said and any key words that might act as optional parameters. 

*Getting excel to talk back (TTS)*








						Speech object (Excel)
					

Office VBA reference topic



					learn.microsoft.com
				





What kind of applications do you think this could be used for?


----------



## TedX (Dec 7, 2022)

This is interesting, firstly thank you MCLIFTO8 for responding. I can tell you I read the tutorial from Wise Owl, then I looked at the Speech Object and dang if I didn't get the subroutine to say hello to me, what a buzz. 

I'll explain using an image, exactly what I was hoping to do.






My worksheet has lots of macros on the quick-access toolbar, using say NSW (indicated), this macro performs a task, which is different than the task for the other macros. So, I'd like to simply say NSW to get the macro to work. All the speech would be doing is simulating a mouse click, in reality, but I just think it would be ultra cool if I had a word for each macro i.e. the title of the macro, like Let's Roll, C6 and so on. What's your opinion on that? I suppose you could go further and say 'Record Macro' to start a new macro or perform any other action. So instead of the computer talking to me, I want to talk to it, instruct it on which macro or action I want it to perform. Is this doable, do you think?


----------



## MCLIFTO8 (Dec 7, 2022)

No worries Ted. I like your mad scientist vibes.


> I just think it would be ultra cool if I had a word for each macro i.e. the title of the macro, like Let's Roll, C6 and so on.



I think so too. My co-worker scoffed at me but then I mentioned the potential utility of standing in a meeting and talking to excel like you would you google assistant. "Excel next sheet" "Excel show percentages" "Excel select Victoria Sales".
At the very least it would be a fun trick to pull on some boomer managers.

I think the utility will need refinement. We can simulate a click of the record macro button using it's three key - key board shortcut using "sendKeys". So we can certainly say, "Excel, record a macro.". However the detailed instructions of what to do in the macro record would probably be a job in itself.

So using voice has it's own overhead of effort that a mouse click just doesn't. You also need to activate the voice record somehow, whether via key presses or a button in your quick access. However a voice command can replace a complicated keyboard shortcut. It can aid in dictation and it can be a crutch for "non technical" excel users, of which there are far too many.

*ex*

Voice turns an unlimited amount of buttons into one button.
You could turn those six ⚠️ buttons into a single "region" button that you say to Excel what region to run.


Voice can help you type quickly.


Voice macros can be given to users instead of a control panel of buttons in a userform in specific circumstances.


So voice commands are niche for a reason but if you want to use them for some cool factor in your workbooks. Why not!


----------



## TedX (Dec 7, 2022)

Okay, so I want to do this one step at a time, so I learn something. Firstly I made a small macro and placed it in my Personal file because initially I want it to work in one specific file but later on, I'd like it to work in as many files as I nominate. 


```
Sub HelloTed()
 
 Application.Speech.Speak "Hello Ted"
 
End Sub
```

This works fine, when I run it as a macro. What I want to do now is, associate it with the action of the file opening, I don't know how to do this. The idea is that every morning when I say Open Excel and it opens then I open this daily file of mine, that it greets me and says hello   

Surely that's not so hard to do??? (perhaps  )


----------



## alexofrhodes (Dec 8, 2022)

you can use AutoHotkey to recognize voice

1. 
	

			HotVoice - Speech Recognition + Volume detection for AHK (C# DLL) - AutoHotkey Community
		


2. 




and to call vba macros








						AutoHotkey/Excel macro menu at main · alexofrhodes/AutoHotkey
					

Contribute to alexofrhodes/AutoHotkey development by creating an account on GitHub.




					github.com


----------



## TedX (Dec 8, 2022)

TedX said:


> Surely that's not so hard to do???


Let me be a little clearer. Let's say I have a working macro called SelectHighestValue, what I want to do is, say the words "Select Highest Value" and when Excel hears me say those 3 words, run the macro. I hope that explains my dream wish. It's sort of like reversing what normally happens when the Computer talks to you, I want to talk to the computer.  🙏 

I just saw AlexOfRhodes response above and am watching the video now, this looks promising. I'll get back to you  👍


----------



## MCLIFTO8 (Dec 8, 2022)

TedX said:


> I open this daily file of mine, that it greets me and says hello



There's an event you can use that as soon as the file opens it runs a macro. You could put your TTS in there I think. 








						Workbook.Open event (Excel)
					

Office VBA reference topic



					learn.microsoft.com
				





```
Private Sub Workbook_Open()
'put this in your workbook, not a module. 
 Application.Speech.Speak "Hello Ted"
 
End Sub
```


----------



## Dan_W (Dec 8, 2022)

MCLIFTO8 said:


> I like your mad scientist vibes.


This had me literally laugh out loud. I couldn't agree more - I like the questions you ask, TedX!

Just one point to make sure I'm on the same page as you both - the link that MCLIFT08 originally posted does, in fact, do speech recognition and not just TTS. Forgive me if I'm missing something, but just looking at TedX's responses, I'm wondering if the points may not be connecting. Here is a link to the start of the Wise Owl tutorial on Speech Recognition (as opposed to TTS): Using your voice to fill in a VBA form . There is a link on that page to a workbook which demonstrates the functionality.

As for automating the recording of macros, I suspect (though haven't checked) that the ExecuteMSO method I referenced the other day on your other thread might be usable here for that... It might be a combination of ExecuteMSO and Sendkeys, actually. I might be wrong though.

_(As a general rule, I like to think anything that can be done in Autohotkey can be done in VBA - though I'm being a bit optimistic with that at times, I think.)_


----------



## TedX (Dec 8, 2022)

MCLIFTO8 said:


> There's an event you can use that as soon as the file opens it runs a macro. You could put your TTS in there I think.
> 
> 
> 
> ...


Sheer Genius, you nailed it, that is exactly what I wanted to do. I had the simple one-line sub in the wrong location. I can't tell you how excited I was to hear those two simple words, it was like the moon landing for me 😂🤣😂 So now, when I open the file it greets me, my next step is for me to say NSW (that's a state in Australia BTW, called New South Wales, abbreviated to NSW), which is different to other states like VIC & QLD etc. I just want to say "Run NSW), I would change my macro name to "run_nsw", so that the name and what I say are the same, if that's too hard, I'd call the macro 'number_one' and then say the words "Number One". Hopefully, the Macro would run (execute). I have some good leads on AutoHotkeys that I still need to work through, so the answer seems to lie there.

I opened a GitHub account that was like landing on an alien planet - everything is weird there 😂 I'm so glad my goto place for learning is right here on Mr Excel 😍


----------



## TedX (Dec 5, 2022)

One of the reasons I like creating macros to speed things along in Excel is that I'm lazy. I assume I am not alone in that department  🤪 

So my question is, is there any voice activation software around (even in Beta) that would let me say commands that would run macros?


----------



## TedX (Dec 8, 2022)

MCLIFTO8 said:


> Voice turns an unlimited amount of buttons into one button.
> You could turn those six ⚠️ buttons into a single "region" button that you say to Excel what region to run.


I went all over Excel.XlRegionLabelOptions enumeration (Excel) and other areas that came up when I searched for Region, but couldn't see any relevant section. How exactly do you make my 6 state macros into a single region? I know what you're thinking, why did I ever reply to this dude 🥰


----------



## MCLIFTO8 (Dec 8, 2022)

TedX said:


> I went all over Excel.XlRegionLabelOptions enumeration (Excel) and other areas that came up when I searched for Region, but couldn't see any relevant section. How exactly do you make my 6 state macros into a single region? I know what you're thinking, why did I ever reply to this dude 🥰



I don't mean an Excel inbuilt function.
I mean you would have your 6 macros but your voice recognition macro would have 6 options depending on what you say and you run the listening sub on your workbook open event / event of your choice / keyboard macro.

This is a very fast and loose psuedo code example with most of it from that Wise Owl tutorial. Don't expect it to just copy-paste in and work.

```
Option Explicit
Private WithEvents ListeningSession As SpSharedRecoContext
Private Grammar As ISpeechRecoGrammar

Private Sub UserForm_Initialize()
    If (ListeningSession Is Nothing) Then
        Set ListeningSession = New SpSharedRecoContext
        Set Grammar = ListeningSession.CreateGrammar(1)
        Grammar.DictationLoad
    End If

    Grammar.DictationSetState (SpeechRuleState.SGDSActive)
End Sub

Private Function ListeningSession_Recognition( _
    ByVal StreamNumber As Long, _
    ByVal StreamPosition As Variant, _
    ByVal RecognitionType As SpeechLib.SpeechRecognitionType, _
    ByVal Result As SpeechLib.ISpeechRecoResult)

    Return Result.PhraseInfo.GetText
End Sub

Sub Victoria()
End Sub

Sub NSW()
End Sub

'.....etc

Sub runThisWhenWorkbookOpens()
   Select Case ListeningSession_Recognition()
   Case "Run Victoria"
      Victoria()
   Case "Run New South Wales"
      NSW()
   Case "Run South Australia"
      SA()
   Case "Run Queens Land"
      QLD()
   Case "Run Western Australia"
      WA()
    Case "Run Japan"
      日本()
End Sub
```


----------



## Jaafar Tribak (Dec 8, 2022)

TedX said:


> I just want to say "Run NSW), I would change my macro name to "run_nsw", so that the name and what I say are the same ..



I don't have a microphone to test this, but based on the link provided by Dan , you can adapt the  ListeningSession_Recognition event listener routine  to run the _run_nsw_ macro as follows :


```
Private Sub ListeningSession_Recognition( _
    ByVal StreamNumber As Long, _
    ByVal StreamPosition As Variant, _
    ByVal RecognitionType As SpeechLib.SpeechRecognitionType, _
    ByVal Result As SpeechLib.ISpeechRecoResult)
   
    With Result.PhraseInfo
        If LCase(.GetText) = LCase("run_nsw") Then
            Call Application.Run(.GetText)
        End If
    End With

End Sub
```


----------



## Dan_W (Dec 8, 2022)

MCLIFTO8 said:


> 日本()


Alas, this won't work in my IDE... I have spent so much time transliterating from Japanese VBA code to romaji just to avoid a sea of errors and red code. Sigh...


----------



## Jaafar Tribak (Dec 8, 2022)

I missed the underscore _ character in my above code

If your voice says *Run NSW* and the corresponding macro is *Run_NSW* then , I think, the following code should work : ( Same logic applies to the other macros\states )


```
Private Sub ListeningSession_Recognition( _
    ByVal StreamNumber As Long, _
    ByVal StreamPosition As Variant, _
    ByVal RecognitionType As SpeechLib.SpeechRecognitionType, _
    ByVal Result As SpeechLib.ISpeechRecoResult)
   
    Dim sMacro As tring
   
    Select Case LCase(Result.PhraseInfo.GetText)
        Case "run nsw", "runnsw"
            sMacro = "run_nsw"
        Case "run vic", "runvic"
            sMacro = "run_vic"
        Case "run qld", "runqld"
            sMacro = "run_qld"
        ' Case othet states ...
    End Select
   
    If Len(sMacro) Then
        Call Application.Run(sMacro)
    End If

End Sub
```


----------



## TedX (Dec 9, 2022)

Jaafar Tribak said:


> I missed the underscore _ character in my above code
> 
> If your voice says *Run NSW* and the corresponding macro is *Run_NSW* then , I think, the following code should work : ( Same logic applies to the other macros\states )
> 
> ...



I'm trying this solution first, I had to change to a different macro because those state ones will wipe out the current pages and start again, which is something I do at night, not during the day.    




The macro I'm trying simply hides a number of columns, it's called unhide_e_to_j and as you can see, I've typed it into the case section. I wasn't sure where to put it, so I tried This Workbook and got the error message shown in the above image. 

So then I placed the code into a new module and spoke the words "unhide e to j" and got some text written into a cell on the open spreadsheet, it was the last cell I used which happened to be selected. So, looking on the bright side, the code when in its own module, does hear that I am speaking and then tries to write it into a cell. That is something, I just need it not to write anything and to make the macro work. If you think my macro names are too confusing and need to be simplified, so that I can just say one short word, then I can try that.


----------



## Jaafar Tribak (Dec 9, 2022)

You will need to place the code in a Class module in order to sink the ListeningSession_Recognition event. The class module could be a userform too.

Add a new class module to your vba project and name the module : *CVoiceListener*


*1*- Class Module code:

```
Option Explicit

Private WithEvents ListeningSession As SpSharedRecoContext
Private Grammar As ISpeechRecoGrammar

Private Sub Class_Initialize()
    If (ListeningSession Is Nothing) Then
        Set ListeningSession = New SpSharedRecoContext
        Set Grammar = ListeningSession.CreateGrammar(1)
        Grammar.DictationLoad
    End If
    Grammar.DictationSetState (SpeechRuleState.SGDSActive)
End Sub

Private Sub ListeningSession_Recognition( _
    ByVal StreamNumber As Long, _
    ByVal StreamPosition As Variant, _
    ByVal RecognitionType As SpeechLib.SpeechRecognitionType, _
    ByVal Result As SpeechLib.ISpeechRecoResult)
 
    Dim sMacro As String
 
    Select Case LCase(Result.PhraseInfo.GetText)
        Case "run nsw", "runnsw"
            sMacro = "run_nsw"
        Case "run vic", "runvic"
            sMacro = "run_vic"
        Case "run qld", "runqld"
            sMacro = "run_qld"
        ' Case other states ...
    End Select
 
    If Len(sMacro) Then
        Call Application.Run(sMacro)
    End If

End Sub
```


*2*- Place the following code In a Standard Module:  (Run the InitVoiceListener routine to initiate the voice recognition)

```
Option Explicit

Private oVoice As CVoiceListener

Sub InitVoiceListener()
    Set oVoice = New CVoiceListener
End Sub

Sub run_nsw()
    MsgBox "You ran: " & vbLf & "run_nsw"
End Sub

Sub run_vic()
    MsgBox "You ran: " & vbLf & "run_vic"
End Sub

Sub run_qld()
    MsgBox "You ran: " & vbLf & "run_qld"
End Sub
```


The above assumes the following:

1- You have already set a reference to the Microsoft Speech Object Library via Tools\References.
2- The names of the macros you want to run with your voice contain an uderscore in the middle.
3- You call the macros saying : Run NSW , Run VIC, Run QLD ...  etc


----------



## alexofrhodes (Dec 9, 2022)

Jaafar's method tested and works, alas microsoft speech recognition is really hard to talk to (or I speak really bad XD).


----------



## TedX (Dec 9, 2022)

Jaafar Tribak said:


> You have already set a reference to the Microsoft Speech Library via Tools\References.






I have this one and I noticed when I scrolled down further that there was this one:





But I can't have them both because I get the following error:





I have not actually tried your solution yet. I had to go and look up what a Class Module was:








						Program with class modules
					

Office VBA reference topic



					learn.microsoft.com
				



Something else I have learned today from this marvellous forum  😍 
I will try this when I can later tonight, I swear I will definitely try to put it all together. I'm keeping all my eyes firmly glazed over


----------



## Jaafar Tribak (Dec 9, 2022)

Use the library that on the second screenshot . That's the one which references the *sapi.dll* file.


----------



## TedX (Dec 5, 2022)

One of the reasons I like creating macros to speed things along in Excel is that I'm lazy. I assume I am not alone in that department  🤪 

So my question is, is there any voice activation software around (even in Beta) that would let me say commands that would run macros?


----------



## TedX (Dec 9, 2022)

Jaafar Tribak said:


> Use the library that on the second screenshot . That's the one which references the *sapi.dll* file.


I got that fixed now, thank you Jaafar. I have two modules as per the image below, however the one on the left is supposed to be the Class Module but I haven't done anything to make it a Class module and I get the red line of text near the top. There are 2 modules, if I can just get the one on the left, Module 148 to become a Class module, I suspect that the red text will turn black. I think I need to do something like Dim abc As New ABasicClass but I'm not really sure. I just renamed Module 148 to *CVoiceListener*


----------



## TedX (Dec 9, 2022)

Okay, now when I'm on a worksheet, and I click on say a row number, I get this error, and my microphone is sleeping 💤💤💤


----------



## Jaafar Tribak (Dec 9, 2022)

*1*- Add the new Class Module:





2- Click on the Properties Window:





3- Change the default class module name from Class1 to *CVoiceListener*





Finally, just paste the class code (post #17) in the class module code pane and save.


----------



## Jaafar Tribak (Dec 9, 2022)

Here is a workbook demo :

VoiceRecognition.xlsm


----------



## Dan_W (Dec 9, 2022)

I haven't had a chance to review the entire thread, or Jaafar's workbook, but I'm really looking forward to it.

The one note of caution I would add, having tried doing this in the past for someone, is that you should probably temper your expectations as to how well the speech recognition works. Also, I'd strongly recommend spending a bit of time with the WiseOwl demo workbook, and trying to say out loud the names of movies you want it to lookup, because you'll start to see that the speech-to-text functionality has certain idiosyncracies you need to be alive to if you're wanting to make it work. I started to go down a bit of a rabbit hole, giving up on expecting it to understand the spoken word, instead trying to give each written and spoken command a SoundEx equivalent and devising some kind of fuzzy matching.

Also, as foreshadowed in the code by @MCLIFTO8, I don't know that your spoken "NSW" is going to remotely resemble what the speech recognition is expecting. As per MCLIFTO8's code, I expect that the spoken command will need to be "Run New South Wales" because NSW will otherwise be something akind to "En Es DoubleYou", and I just don't know that the speech recognition system has that kind of power... I vaguely recall that the system did it's best recognition with single words, or maybe I'm getting that mixed up. I remember that *@Gokhan Aycan *was giving me some guidance last time.

Mind you, it's been a while since I looked at it, and I certainly didn't have the benefit of Jaafar's code to help me. Looking forward to learning more about it again.


----------



## TedX (Dec 9, 2022)

Dan_W said:


> The one note of caution I would add...



Thank you very much for your advice, I bet you are correct, I suspected as much days ago about my macro naming conventions being able to be used as expressions, the speech would actually recognize. Believe it or not, I actually have a real job that annoys me to distraction and unbelievably they actually wanted me to do some real work, which has slowed me down. I will get this going because too many people have put too much effort into me and I won't let you down. It will take a few hours/days however and of course, that **** soccer world cup is also getting in the way 😂🤣😂


----------



## TedX (Dec 9, 2022)

Jaafar Tribak said:


> You will need to place the code in a Class module in order to sink the ListeningSession_Recognition event. The class module could be a userform too.
> 
> Add a new class module to your vba project and name the module : *CVoiceListener*
> 
> ...



Hello again, I've created a simple macro called one, so all I should have to do is say 'one' and you would think that it would be able to recognize that single word relatively easy. After making the macro, I made some slight changes, as you can see in the image below, to correspond with the case and MsgBox. Unfortunately when I ran the InitVoiceListener() I got the error message. I just made the macro in the workbook I am using and ran the macro to make sure it's woring. Any ideas why I got that error message and at the same time, can you closely look at all three modules, the Class module on the left and two other standard modules. Is anything showing up that's shopuldn't be there. There are no macros named run_new etc. perhaps that is screwing it up, I thought if I could switch on the listener, andonly said 'one' that only that part of the code would run, do you think I should clean out the parts of the code that don't yet exist, like those cases for the other states. I really do have names for all the macros but they are long and stupid and if I can just get 'one' to work, I'll rename them all, as in 'two', 'three' and so on. Anyway, can you spot the reason for my error?


----------



## TedX (Dec 9, 2022)

Okay, new information: I cleared out the superfluous code that pointed to other macros and ran the sub InitVoiceListener() which appeared to work, in so far as I ran it and nothing happened, so I assume it was listening. Then I spoke one word, it was 'one' and that's when the error appeared. That means it was listening because the error only appeared after I spoke, after it heard me speak. I don't know if this is helping anyone, but I'll bet the city of Tucson to a Cuban cigar that I am only one step away from making this work 🙃😉


----------



## Dan_W (Dec 9, 2022)

You can check to see whether or not a certain part of the code has been executed by using *Debug.Print* statements. I find it's helpful to check to make sure all necessary parts of the programs flow have been executed. So you may want to put 

```
Debug.Print "Listening Session - Recognition - Initialised"
```
or something like that at the start of the relevant subroutine.

Also, just quickly, you don't have subroutines that share the same name, do you? I note that you have a *Sub One *in two separate modules. You want to avoid do that as much as possible, otherwise VBA will start complaining about ambiguity something something. If I'm saying something out-of-turn, or it's something you already know and I've just failed to pick it up on my quick skim read, my apologies....


----------



## TedX (Dec 9, 2022)

Dan_W said:


> You can check to see whether or not a certain part of the code has been executed by using *Debug.Print* statements. I find it's helpful to check to make sure all necessary parts of the programs flow have been executed. So you may want to put
> 
> ```
> Debug.Print "Listening Session - Recognition - Initialised"
> ...


Ah Ha, you gave me a lead regarding debugging, so here is where the error actually occurs:


----------



## TedX (Dec 5, 2022)

One of the reasons I like creating macros to speed things along in Excel is that I'm lazy. I assume I am not alone in that department  🤪 

So my question is, is there any voice activation software around (even in Beta) that would let me say commands that would run macros?


----------



## TedX (Dec 9, 2022)

TedX said:


> Ah Ha, you gave me a lead regarding debugging, so here is where the error actually occurs:
> 
> View attachment 80530



Can anyone see why this is throwing an error?






It's a Run-time error '1004'. I can manually run a macro named 'one', what would stop the code from being able to run it? Any suggestions?  🙏


----------



## Dan_W (Dec 9, 2022)

Do you still have two Sub One() routines (modules 148 and 149?)?


----------



## TedX (Dec 9, 2022)

Dan_W said:


> Do you still have two Sub One() routines (modules 148 and 149?)?


Yes I do 148 is a sample macro called one that just colours a few cells in. 149 is where I've put the InitVoiceListener and MsgBox. What are you thinking Dan_W?


----------



## Dan_W (Dec 9, 2022)

Im thinking that's the source of your error. As I mentioned in my previous message, you should avoid subroutines of the same name because VBA won't know which one you want it to run


----------



## TedX (Dec 9, 2022)

Dan_W said:


> Im thinking that's the source of your error. As I mentioned in my previous message, you should avoid subroutines of the same name because VBA won't know which one you want it to run



Of course, the MsgBox is the problem, I only put that in because the code from the original tutorial had it in, I guess to just act as proof that something happened. It worked, it 100% worked, this is the part coming up where I thank you blubbering and spluttering like a baby 🤣😂🤣 This has been a marathon and there are many who have helped along the way. I guess the fact that I'm so thick, actually expanded this thread far longer than it need to be. Which is good because there must be other dopey people like me out there. Yes you did say the issue earlier and what's more relevant is that you came back a second time and said it again. I wasn't thinking the MsgBox reference was actually a subroutine in its own right, I was thinking it's just a reference to my one and only macro of that name but as you have driven home to me, there were actually two macros of the same name. Who would have ever thunk it 😁 So with the greatest of pleasure I'm going to mark this thread solved, I learned a lot, and it was the little things, like Class Modules are different to Standard Modules (LOL) and make sure every macro has only one unique name. I learned not to call your macros long-winded descriptive names like Sub I_will_never_call_a_macro_this_lengthy_name_ever_again()

I want to thank *MCLIFTO8, alexofrhodes, Dan_W and Jaafar Tribak you all helped heaps, thank you very much!


----------



## Dan_W (Dec 9, 2022)

You're very welcome. I was curious to hear what you thought of the speech recognition system. Do please report back if you end up coming up with a suggested way of using it, etc.


----------



## TedX (Dec 9, 2022)

Dan_W said:


> You're very welcome. I was curious to hear what you thought of the speech recognition system. Do please report back if you end up coming up with a suggested way of using it, etc.



Absolutely Dan_W, you can't get rid of me easily, now that I've had a taste of this   😉 
Plus, I am now a Board Regular 🤪 pity anyone I try to help 😂


----------



## TedX (Dec 10, 2022)

Hi again (yep it's me), I just can't get the second case to work (see image) I called it three, in fact I can't even find three when I search for it but I can step into it to make it work. Is this a syntax problem or a naming convention issue or just me being dumb?


----------



## Dan_W (Dec 11, 2022)

Well, on the plus side, it's not a syntax problem - you wouldn't be left with any doubt if it were. VBA is pretty quick to tell you about syntax issues.

It's hard to say without having a clearer understanding of the how the project is laid out - I assume that the the module on the left is a class module, and the middle and right ones are standard modules? On that, your module names (148 and 149) are starting to give me panic attacks at just how big your VBProject is.


TedX said:


> I called it three, in fact I can't even find three when I search for it but I can step into it to make it work.


I suspect that this the answer to your problems somehow - I'm not entirely sure what you mean when you say you search for it but you can't find it... Do you mean you search for it with the Macros Dialog Box (Alt F8) or you literally can't find the string "three" in the Find Dialog Box?


----------



## TedX (Dec 11, 2022)

Dan_W said:


> Well, on the plus side, it's not a syntax problem - you wouldn't be left with any doubt if it were. VBA is pretty quick to tell you about syntax issues.
> 
> It's hard to say without having a clearer understanding of the how the project is laid out - I assume that the the module on the left is a class module, and the middle and right ones are standard modules? On that, your module names (148 and 149) are starting to give me panic attacks at just how big your VBProject is.
> 
> I suspect that this the answer to your problems somehow - I'm not entirely sure what you mean when you say you search for it but you can't find it... Do you mean you search for it with the Macros Dialog Box (Alt F8) or you literally can't find the string "three" in the Find Dialog Box?



That's correct, I can't find the subroutine named 'three', but I can run it by stepping through it. Weird hey? I have been working on this program for three years and have 149 modules, there are several hundred macros. I did redesign the whole thing several times. I know what you're thinking, I should have just started again and built a new project and that way would only have a much smaller number of macros. However, all names are unique, there is no 'three', except there is. 

Just on the code in the Class Module, is the case set out correctly?


----------



## TedX (Dec 5, 2022)

One of the reasons I like creating macros to speed things along in Excel is that I'm lazy. I assume I am not alone in that department  🤪 

So my question is, is there any voice activation software around (even in Beta) that would let me say commands that would run macros?


----------



## TedX (Dec 11, 2022)

I just took the 'three' subroutine out, and I currently have what's in the image below. It works 100%, this is where I left off yesterday. Now I want to simply add a second routine, otherwise, all the coding has been just for one command, which is hardly worth it. I want about 12 subroutines, I really don't care what they are called because the subroutine can simply call another macro, like the working example below shows. When I say one, a new instance of a worksheet opens for me, which is all preformatted. This is so cool, but I would like another 11 voice commands to work as well as this one.


----------



## Dan_W (Dec 11, 2022)

There is a point to be made about the size of your workbook, and how you'd be better off separating out: (1) the program your working on; and (2) the tools you're using, not least because with 149 modules, and who knows how many procedures, I'm surprised you're not bumping into conflict errors more often.

There is also a point to resolved about you not being able to find "Sub three" when you search for it, because that's not really 'a thing'. Do you have any of the find dialog settings left on maybe? One very quick and easy way of finding the procedure is to mimic what Application.Run does by literally doing that manually in the Immediate Window, and executing it. So:


```
Application.Run "three"
```

And see what happens. Alternatively, you could execute Application.Goto "three", which will take you straight to the procedeure (assuming there is only one named that in your workbook, and you don't have any modules called 'three'... which, as I type this now, is starting to feel like its becoming the frontrunner of possible culprits. But the absolutely surefire way of finding the procedure is to preface it with the name of the module! So:


```
Application.Run "Module148.three"
```

At this juncture, I would suggest giving your modules and subs more meaningful names. It makes sense to use simple words for the speech recognition commands, but the actual names of subroutines don't have to be same as the command.


----------



## TedX (Dec 11, 2022)

Dan_W said:


> There is a point to be made about the size of your workbook, and how you'd be better off separating out: (1) the program your working on; and (2) the tools you're using, not least because with 149 modules, and who knows how many procedures, I'm surprised you're not bumping into conflict errors more often.
> 
> There is also a point to resolved about you not being able to find "Sub three" when you search for it, because that's not really 'a thing'. Do you have any of the find dialog settings left on maybe? One very quick and easy way of finding the procedure is to mimic what Application.Run does by literally doing that manually in the Immediate Window, and executing it. So:
> 
> ...



I couldn't agree with you more Dan and I got rid of 'three' entirely and used a much better name of 'roll', which is meaningful to me. Then BOOM 🔥🔥🔥🔥🔥🔥 it worked flawlessly. After making sure my microphone was on and listening, I ran the voice listener subroutine (InitVoiceListener) in module 149 as shown in the final (*yes, the very last image*) and then I boomed out in a beautiful Aussie accent that magnificent word 'roll', this called into play around about a dozen smaller macros which were called by a single macro which wiped everything out of my worksheets ready for the next day.

Then I eloquently spoke that magnificent word 'one', which open another worksheet over the top of the currently open worksheet, ready for me to transfer the new day's data into it. That macro also calls into play another 4 macros. Let me tell you this, when I first started doing this project, about 3 years ago, to do, up to this point manually was taking me more than 2 hours, if I had 6 meetings to do, which there are always 6 or more on a Saturday and Wednesday. I have through the power of VBA slowly gotten that time down to less than 1 minute and now, I don't even have to click a mouse or tap a keyboard, I just say a few words. 

No one should ever say to me that VBA and Excel aren't the best programs in existence, because they will regret it 😂 

Thanks to everyone that helped - this thread is now, well and truly closed, but of course available for others to read if they wish to harness the power of speech recognition to run macros in Excel 💘


----------



## Gokhan Aycan (Dec 16, 2022)

I only got aware of this thread today, and I see I am a bit late. If you will use speech recognition, make sure you perform speech training ideally couple of times.

How I used SpRec is a bit different. I used InProc instead of shared. iirc in shared Excel itself/or Windows can be listening to commands.
Another difference is I used an XML file for grammar rules. It is different than free dictation, and you need to use certain patterns.

One thing I noticed was as soon as you enable recognition it starts to listen even to surrounding sounds, so it can recognize someone else or a TV etc. Even it doesn't recognize, it is possible to interfere with what you are saying. So I used a push-to-talk kind of feature. Any form of recognition is dismissed unless CTRL key is pressed.

Also the likelihood of a successful recognition increases if you use 2 or ideally 3 words.

You have a very simple scenario at least for the moment, but it gets complicated fast when you start to pass also parameters uttered in human language  Pasting how a grammar rule XML looks like (they are of course only meaningful for my own app).


----------



## Dan_W (Dec 16, 2022)

Gokhan Aycan said:


> I only got aware of this thread today, and I see I am a bit late. If you will use speech recognition, make sure you perform speech training ideally couple of times.
> 
> How I used SpRec is a bit different. I used InProc instead of shared. iirc in shared Excel itself/or Windows can be listening to commands.
> Another difference is I used an XML file for grammar rules. It is different than free dictation, and you need to use certain patterns.
> ...


Oh wow. This is awesome. I'm very glad I remembered to tag you in this! I may pester you with follow up questions. Thank you!


----------



## TedX (Dec 16, 2022)

Gokhan Aycan said:


> I only got aware of this thread today, and I see I am a bit late.



Hi Gokhan, your contribution is amazing, it's well above my level, but I can sense it's an awesome bit of code. As for your tips yes, you are accurate. Since I got mine working, I did in fact hammer the learning, I added quite a few words individually saying them over and over, listening to how I sounded. It's funny how, I would say some words differently than normal simply because I was recording it. A form of self-sabotage perhaps, the mind is weird, well my is anyway    😂   

I got the project I have, fully sound operational, I can speak through it, running macros doing a variety of tasks, it's super cool and anytime I get a visitor, I go into an academy award performance saying words and stuff just happens on the screen, these 'ordinary' people think I'm a magician. Yes, I know I'm a flipper but heck I'm having fun showing off 🤪


----------

