Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Connect to Excel Failure
#1
I am getting the following message when trying to connect to Excel:
Error (RT) in VV_LoadExcel: Failed to connect to Excel.
Excel must be running. If fails anyway, try to run this macro in separate process as User. Set it in Properties.


This is the code that generates the error:
/exe 1
function int'Row
out "VV_LoadExcel: Row is %i" Row

int WaitTime = 0.2
str data
ExcelSheet VV_Survey.Init("Work") ...... fails here.
...


I am running Vista/Excel 2007 and Excel is up and running. This function is called by another macro, and it worked fine under XP/Excel 2000. I have selected to run the macro in a separate process as User, but still get this error.

I run under an account without admin privileges, but I am able to connect with Excel using a simple demo program from the Help topic on Excel and it works fine.

Any ideas on what might be wrong?
#2
I finally got this to recreate the error...

If I open up excel file and then run the function without ever activating the Excel window QM will return this error.

I think if you just have QM activate Excel at the top of the function, you'll be fine.

Something like:
act child("[\0-9a-z]*" "" win("Microsoft Excel - [\0-9a-z]*" "XLMAIN" "" 0x200) 0x200)
#3
It still fails with the same error message. It is different though, in that now when the function is called, I see the Excel window border and the currently selected cell flash twice, but then it dies at the Init statement. Without your suggested statement that didn't happen.
#4
When checked 'run in separate process', it inserts " /exe 1" at the beginning of the macro.
Then, when you run the macro, it creates and runs YourMacroName.exe file in My Documents\My QM folder.
How it works if you doubleclick the exe file in Windows Explorer?

--------

Make sure that Excel runs not as administrator.
Also, Excel must be running in the same user account as your exe. Look in Task Manager, maybe they run in different accounts.
#5
Yes, running the .exe directly works fine. Both Excel and QM are running in the same non-admin account.
#6
Here is a bare bones test that demonstrates the problem I'm experiencing:

Created the following macro:

act child("[\0-9a-z]*" "" win("Microsoft Excel [\0-9a-z]*" "XLMAIN" "" 0x200) 0x200)
ExcelSheet ExcelTest.Init
ExcelTest.SetCell("Testing" 1 1)

If the first line is commented out, I get the "Failed to connect to Excel" error message, and nothing happens to the Excel window.

If the first line is not commented out, I get the "Failed to connect to Excel" error message, but the Excel window and the currently selected cell both flash quickly a couple of times first.

If I make exe, and run the exe by double-clicking it, cell A1 is loaded with "Testing", as expected.



Is this a bug, or is something mis-configured on my PC?
#7
The macro must be

Macro Macro1477
Code:
Copy      Help
;/exe 1

ExcelSheet ExcelTest.Init
ExcelTest.SetCell("Testing" 1 1)

If it fails anyway, I don't know what could be the reason. On my Windows 7 computer works well. Tested on admin and on standard user accounts.
#8
Also try to run QM as user. Set it in Options -> General. Then don't need /exe 1.
#9
Changing to UAC:run as User in the General tab seems to resolve the Excel connection problem, at least in my small test case.

However, now it seems that I am unable to access the application from which I am getting the data that I want to load into Excel. That application has to run under admin. So would you expect this new failure as a result of setting run as User? Even though I am able run the application interactively on my non-admin account (after being prompted for admin password at startup)?

If so, I guess I might have to log in as admin and see if I can then run my QM application successfully?
#10
Quote:However, now it seems that I am unable to access the application from which I am getting the data that I want to load into Excel. That application has to run under admin. So would you expect this new failure as a result of setting run as User?

Yes. When QM runs as User, macros running in QM context cannot do many things that require admin privileges. Therefore it is better when QM runs as admin. Or you can set to run these macros in separate process as admin.

Quote:If so, I guess I might have to log in as admin and see if I can then run my QM application successfully?
Yes, try it.

Or you can turn off UAC. Then all similar problems will not exist.
#11
Thanks for the help!
#12
Update on this problem:

I tried running with UAC turned off, but then my data application fails to start, so that's not an option.

Now, I'm trying to run logged in as admin to see if that will work, and am encountering the following:

I have an initialization macro (Init) that defines constants and arrays and then calls another macro, Portfolio, that uses those variables. I set "Run in separate process" for Portfolio to eliminate the Excel connection failure, but then when I run Init, I get an "array is not created" error in Portfolio when trying to access an array element defined in Init. As soon as I comment out the "/exe 1" at the top of Portfolio, the array element is accessed as expected (but then of course it fails on the Excel connect).

Any reason you can see that the array access would fail? By the way, other variables defined in Init are accessed with no problem, and I have put "out" statements before and after the array definition in Init, and they both execute, and there is no error when the array is defined.
#13
Macros running in separate process cannot access global variables of macros running in QM or other processes. Each process has its own global variables. To initialize them, call your init2 function in each process.

I don't recommend to have many global variables. Especially those that are defined and initialized in init2.

From QM Help, 'Make exe' topic:

Quote:If you use global variables that are initialized at QM startup, you should add the initialization code to the exe, or these variables in exe will be empty. For example, call the initialization function at the beginning of the main function (you can use #if EXE to skip it when running in QM). This is not needed for global variables that are initialized by constructor. This is not needed for predefined global variables.
#14
I have been using QM on excel 2013 without issues. Now have upgraded to office 365 and still works fine, except in an specif machine that have used .exe macro for a long time on excel 2013.
That machine have the same configuration as others and I have reinstalled office365 twice, and still appearing following error message at runtime, at the "ExcelSheet es1.Init" command line :   "failed to connect to Excel. Try to run this macro in separate process as User." .
I have tried:
1) Run from a QM .exe file
2) Run in QM console
3) Selecting the "Run as" option to "UIAccess" and as "User", in Tools->options->General Tab.
4) including and retiring " /exe" 1 at the top of script.
and the error messaage still remains on that machine, although it works well in other ones.

Is there any recommendation to solve this issue.
Thanks in advance


Forum Jump:


Users browsing this thread: 1 Guest(s)