KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Error message the first time running a custom command
Topic Summary:
Created On: 04/23/2022 03:44 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 Error message the first time running a custom command   - Alan Cantor - 04/23/2022 03:44 PM  
 Error message the first time running a custom command   - Robert Snow - 07/31/2022 04:28 PM  
 Error message the first time running a custom command   - Mav - 08/01/2022 01:44 AM  
 Error message the first time running a custom command   - Alan Cantor - 08/01/2022 10:20 AM  
 Error message the first time running a custom command   - Edgar - 08/03/2022 09:39 AM  
 Error message the first time running a custom command   - Alan Cantor - 08/03/2022 03:28 PM  
 Error message the first time running a custom command   - Mav - 08/04/2022 02:04 AM  
 Error message the first time running a custom command   - Alan Cantor - 08/04/2022 10:32 AM  
 Error message the first time running a custom command   - R. Wilke - 08/04/2022 11:22 AM  
 Error message the first time running a custom command   - Mphillipson - 08/04/2022 01:17 PM  
 Error message the first time running a custom command   - kkkwj - 08/04/2022 03:06 PM  
 Error message the first time running a custom command   - Mphillipson - 08/06/2022 03:33 PM  
Keyword
 04/23/2022 03:44 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4345
Joined: 12/08/2007

I have a custom Dragon command for Excel called "good bye <values> <values>.

The first time I run this command after launching Dragon, I get this error message:

---------------------------
MyCommands
---------------------------
The Macro contains the error:

MyCommand: "good bye 5 8"
Line:    5
Position:    0
Description: (10096) ActiveX Automation: no object currently active. -

Please use MyCommands Editor to make the appropriate corrections.
---------------------------
OK   
---------------------------

I clear the error message, repeat the command, and voilà! The command works, and continues to work for as long as Dragon is running.

The same thing happens the next time I run Dragon.

What might cause a command like this to fail the first time?

Not sure this is relevant, but as part of this command, I set the Reference to "Microsoft Excel XX.0 Object Library (X.X)". [The values of X depend on the Excel version.]

 07/31/2022 04:28 PM
User is offline View Users Profile Print this message

Author Icon
Robert Snow
Top-Tier Member

Posts: 206
Joined: 04/18/2017

I'm sure you thought of this but could it have anything to do with system restart. 



-------------------------

Robert Snow
Germantown, WI

 08/01/2022 01:44 AM
User is offline View Users Profile Print this message

Author Icon
Mav
Top-Tier Member

Posts: 523
Joined: 10/02/2008

[...]The Macro contains the error: MyCommand: "good bye 5 8" Line:    5 Position:    0 Description: (10096) ActiveX Automation: no object currently active. [...]

What is the command in line 5?

Without knowing this, it's next to impossible to tell for sure what causes the problem.

Could it be that you're starting Excel and the target document simply hasn't been initialized yet?

 

hth

mav

 08/01/2022 10:20 AM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4345
Joined: 12/08/2007

Hi Mav,

My practice is to add blank lines to my scripts to make them easier to read. In this case, Line 5 is blank!

1 Sub Main
2
3 Dim objExcel As Excel.Application
4 Set objExcel = GetObject(, "Excel.Application")
5
6 Dim StartRow, EndRow, RangeRow As String
7
8 Let StartRow = ListVar1
9 Let EndRow = ListVar2
10
11 Let RangeRow = StartRow & ":" & EndRow
12
13 objExcel.Rows(RangeRow).Delete
14
15 End Sub

When I remove the blank lines from the script, the instruction that triggers the error message is "Dim StartRow, EndRow, RangeRow As String"



 08/03/2022 09:39 AM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1276
Joined: 04/03/2009

Originally posted by: Alan Cantor Hi Mav, My practice is to add blank lines to my scripts to make them easier to read. In this case, Line 5 is blank!

1 Sub Main

2

3 Dim objExcel As Excel.Application

4 Set objExcel = GetObject(, "Excel.Application")

5

6 Dim StartRow, EndRow, RangeRow As String

7

8 Let StartRow = ListVar1 9 Let EndRow = ListVar2

10

11 Let RangeRow = StartRow & ":" & EndRow

12

13 objExcel.Rows(RangeRow).Delete

14

15 End Sub

When I remove the blank lines from the script, the instruction that triggers the error message is "Dim StartRow, EndRow, RangeRow As String"

 

Three thoughts…

1) it's highly probable that line 4 "Set objExcel = GetObject(, "Excel.Application")" is the culprit. Try moving it down below line 11 (Let RangeRow…); The error message should now show the line number just above the "Set obj…". This will indicate that the "Set obj…" line is the actual culprit.

2) can you provide a link to the documentation for "GetObject"?

3) a possible workaround, create a custom startup script for Excel which you would always use in place of "start Excel": (In pseudocode)

Sub Main

     ShellExecute "[Fully qualified to excel]"

     [Wait 1] however long it takes for Excel to fully open

     Dim objExcel As Excel.Application

     Set objExcel = GetObject(, "Excel.Application")

End Sub

You could get fancy and also pass in the filename if you wanted but that might actually make matters worse. Then, your row deletion script Would remain exactly as is (with another call to "Dim obj…" and "Set obj…". This might "prime the pump" <shrug>.

 



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 08/03/2022 03:28 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4345
Joined: 12/08/2007

Hi Edgar,

I think you're onto something. Maybe the pump isn't getting primed!

I like your ideas, especially your pointing out that there's nothing sacrosanct about the position of this line...

Set objExcel = GetObject(, "Excel.Application")

...as long as it appears BEFORE the line that actually deletes cells. So I tried moving it around the script.

The error message signals a problem with the line AFTER the "Set objExcel" instruction, whatever that line happens to be.

Here's another clue: I'm finding that I must exit and restart Excel every time I make a change to the script. If I don't, the command doesn't do anything.
 08/04/2022 02:04 AM
User is offline View Users Profile Print this message

Author Icon
Mav
Top-Tier Member

Posts: 523
Joined: 10/02/2008

The error comes from the call to GetObject() for sure.

Seems as if Dragon counts lines differently than the rest of the world. If it were 1 lower than the real number then I'd suspect the lines to be 0-indexed (the first line would be #0 and not #1), but with the number being one HIGHER than the real error line I can only assume a bug in the scripting engine.

Anyway, the GetObject() function is part of the Basic Scripting Runtime.

The description on the Nuance page is quite short, unfortunately.

I've attached the Microsoft Windows Scripting help file, where the function is documented in more detail.

The error message states that the object is currently not active. So Excel is either not running or not ready yet.

If you don't want to access an object that's currently active (this is what GetObject does), you can use CreateObject() to start the application.

Depending on your use case, this might be more suitable for you.

 

hth

mav



script56.zip
script56.zip  (2792 KB)

 08/04/2022 10:32 AM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4345
Joined: 12/08/2007

The problem just gets stranger and stranger.

I reviewed my other custom commands for Excel that use almost the same code.

None of the other commands exhibit the strange behaviour of failing once, and then working.

For example, this script works, and it's very similar to the one that is causing mischief:

Sub Main

' Set the Reference to "Microsoft Excel XX.0 Object Library (X.X)"
' The values of X depend on the Excel version

SendDragonKeys "{Esc}"

Dim objExcel As Excel.Application
Set objExcel = GetObject(, "Excel.Application")

Dim Target, ColumnA, ColumnB, Row As String

Let ColumnA = Left(ListVar1, 1)
Let ColumnB = Left(ListVar2, 1)
Let Row = ListVar3
Let Row = Replace (Row, ",", "") ' Strip commas from Row number, e.g., 1,000 -> 1000

Let Target = ColumnA & ColumnB & Row

objExcel.Range(Target).Select
End Sub

Since the above script works as expected while a similar one fails and then works, could there be an issue with the instruction that's doing the heavy lifting? This one:

objExcel.Rows(RangeRow).Delete

I don't remember how I came up with this line. I probably copied the code from a website, or I came up with it myself through trial and error.
 08/04/2022 11:22 AM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 7876
Joined: 03/04/2007

Many many years ago, I did some scripting in VBA for Excel, and although I have lost all my notes, I can well remember that it wasn't the easiest thing to do. I also remember that I spent quite a few days digesting the documentation and the tutorials, of which there are zillions around, before I could even begin with it.

Bottom line being that, in order to create and instantiate an object properly, you have to follow the object model scheme, which goes something like "Application - Workbook - Sheet - Range - ..." or thereabouts. If I recall correctly, one of the crucial points was also being able to determine whether Excel is already active and you want to talk to that active instance, or create a new one, which makes all the difference.

As regards handling of objects in general, also bear in mind, that treating them properly also requires deleting them properly when you're done with them, such as by setting them to nothing for instance, because if you don't, you will cause a leak which might leave the scripting engine hanging, and Dragon along with it, if the engine is called from within Dragon, at worst.

Welcome to the world of 00P, although just in miniature!


-------------------------



No need to buy if all you want to do is try ...

DragonCapture KB Download (Latest)
DragonCapture Homepage

 08/04/2022 01:17 PM
User is offline View Users Profile Print this message

Author Icon
Mphillipson
Top-Tier Member

Posts: 297
Joined: 09/22/2014

Is there any difference if Excel is already running and when it is not?

I think I remember that Get object means that Microsoft Excel has to exist otherwise you have to use the create object instead. Where the create object will create a new instance of Microsoft Excel. And the script will not run until it is loaded.

-------------------------

Thanks Mark


 


Dragon Professional Advanced Scripting/KnowBrainer Scripts
Video Examples of Coding by Voice

 08/04/2022 03:06 PM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 942
Joined: 11/05/2015

My two bits:

RW is correct - none of your scripts clean up after themselves. You need 'set objExcel = nothing' after you are done with the object. Otherwise COM garbage is not cleaned up and "code" may try to use old objects that are invalid.

Edgar and Mark are also correct - GetObject expects excel to be running (I think), and may return a null object. Oh wait, didn't the error message say "ActiveX Automation: no object currently active."? :-)

To write your scripts properly they should check the value of objExcel something like this:

' get the running excel instance
set objExcel = GetObject(...)

' abort if Excel is not running
if objExcel = nothing then
MsgBox No Excel object found!
Exit Function, Exit Sub, or whatever
endif

' now use the valid Excel object
Your code here


-------------------------

Win10/11/x64, AMD Ryzen 7 3700X/3950X, 64/128GB RAM, Dragon 15.3, SP 7 Standard, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Amazon YUWAKAYI headset, Klim and JUKSTG earbuds with microphones, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and fat mouse

 08/06/2022 03:33 PM
User is offline View Users Profile Print this message

Author Icon
Mphillipson
Top-Tier Member

Posts: 297
Joined: 09/22/2014

I believe get object will raise an error if Microsoft Excel not running

 

The following CODE will create a new instance of Microsoft Excel, but would not raise an error:

Dim ExcelApplication As Object 'Excel.Application
Set ExcelApplication = CreateObject("Excel.Application")



-------------------------

Thanks Mark


 


Dragon Professional Advanced Scripting/KnowBrainer Scripts
Video Examples of Coding by Voice



Statistics
32323 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 1 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 526 guests browsing this forum, which makes a total of 527 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2022 FuseTalk™ Inc. All rights reserved.