Reading Excel updates with UFT - excel

Hi everyone,
I'am using HP UFT for testing.
I get data from an Excel file and also write data to the same Excel file.
My issue is that when i write data to the Excel file, I can't use it until the test is closed and UFT stops running (UFT won't read it, it's still blank to it).
I need a way to update UFT "view" of the Excel while running, i can't just close and open again the Excel file while test is still running.
Language used: VBScript
Can you help me?
Thank you all

You should use the UFT DataTable. The DataTable utility object gives you ways to import the Excel File programmatically at the beginning of the Test, write the files to there and when it ends, dump it back to a file. As a Bonus, you would also be able to see the DataTable content in the RunReports at the end(under the Data Tab)
Do not forget that everything you do on the DataTable while running the test is written into the memory only. In case the test cannot reach the end where you persist it again, all is lost. You can try error handling with On Error Resume Next, Recovery Scenarios or Class_Terminate based destructors (Create and instantiate a Dummy class, and if the test crashes and stops the Class_terminate will automatically be called where you can do cleanup activities.

Related

sort program breaking after second file attempt

I have developed a VBA/excel program that scans an excel file or a pdf file to extract relevant data and save to a seperate sorted sheet.
The vba/excel program runs fine on my machine but on my coworkers computers it only runs one of the files and then throws an error when trying to run a second file unless the vba/excel program is closed and then reopened.
I thought this could have something to do with the connections related to the queries not being cleared, but after attempting to add code to clear the connections as well my code resorted back to the original problem I was having... VBA Method 'SaveAs' of Object '_Workbook' faild, but only on one computer
What is going on here? Thanks in advance for any ideas

Bizzare Database.Close (DAO) issue in Excel Userform

I have an Excel Add-in (with a Userform) which connects to an Access database (using DAO) to perform various functions. I've been using this combo for over a decade. Neither the code in Excel nor the database have been changed recently. Just last week, a user reported that one of their functions was taking much longer than usual, so I looked into it. It ended up that the function itself ran just fine, but when the code was cleaning up and ran db.Close it hung up. It doesn't produce an error, it still eventually succeeds, but it takes around a minute to close the db and move on.
I'll go through all of the symptoms and attempted solutions to see if anyone else has any ideas because I'm at a loss.
This only happens when you run db.Execute. I can open the database and close it right away and it closes just fine. If I open it, run a SELECT query to populate a recordset, then close it, it also closes just fine. But if I open it and run a single UPDATE/SELECT INTO/INSERT/ALTER/DROP statement, the Close method will take a minute to run.
My first thought was to compact the db. I cleared out several unused, old tables and compact/repaired, but this did nothing. Same problem.
My next attempt was to recreate the db. I made a brand new TEST db, imported all of the tables from the old one, pointed my Excel Add-in at the new db and did the same tests. Same results.
My next attempt was to try moving it to a local drive (it's on a network share). This slightly reduced the hang at Close, but it's still there. Not that it matters, because this db has to be hosted on a network share.
My next attempt was to delete a bunch of tables from my TEST database. I cleared out about half of them and the hang at Close was reduced a good deal. Clearing out even more reduced it even more. Deleting all but one table eliminated it. So now I know my problem has to do with the size of the db, but why? It maxed out at 500MB after the compact, which isn't that large. It's been running just fine for years. Why all of a sudden would the size/number of tables be such a huge issue? I obviously can't delete all of the tables in the production database just to solve an issue with Closing the connection.
As I mentioned, this code has been around a long time and the prod db was actually in Access 2000 format (mdb), so my next attempt was to change the format. I tried importing it all into both an Access 2003 format (mdb) and the latest Access 2016 format (accdb). The results were the same.
On a lark, I figured I'd trying hitting the db from somewhere other than the Add-in (on the off chance that the problem was in my Excel file). I copied and pasted my test code into a Word 2016 module... and it ran just fine.
That's odd.
So then I tried a brand new Excel file. Also ran just fine.
So I go back to my Add-in and try the code pasted into a Module.
Again, runs fine.
??
So I open the Userform and run my test code again. Hangs up.
??????
I create a brand new Excel file, make an empty Userform, paste my test code in the form's Initialize event.... hangs up.
I immediately run that same code in a Module afterwards... still hangs up. Even though a minute ago it ran just fine in a module in a different file.
But if I close the file, open a new one, paste in the code WITHOUT opening the Userform, and run it, it works fine. Creating/opening a userform will cause all subsequent attempts to run the code to hang.
So here's the Cliff's Notes version:
Excel 2016 DAO connection to large-ish Access database hangs on db.Close under the following circumstances:
1) The db is large (deleting most of the tables helps but obviously isn't a solution).
2) You have opened any Userform at any time during your Excel session. All attempts during OR after the opening of the form, no matter where the code is run from, will hang. Running the code before opening a Userform does not hang.
These results are duplicated on multiple Windows 7 machines, all with what appear to be the latest updates to Office.
EDIT: I was able to try this out on a remote machine running Excel 2013 and there is no hang (using the original Add-in/db that first exhibited the problem). However, that machine is in our data center which is the same place that the network shares are located, so there are at least two possible reasons why it doesn't hang: 1) Different version of Excel and 2) Different/faster network connection.
If you're wondering why I'm using DAO instead of ADO, it's because of what these functions do (lots of stuff with looping through Tabledefs to modify indexes and even create/modify the table Description, which can't be accessed via ADO. If it weren't for all that, I'd just switch to ADO and be done with it. It's possible that I might be able to come up with ADO alternatives/work-arounds for everything that it's currently doing, but I'd rather not rewrite this entire Add-in if I can help it.
I'm at a complete loss on this one, so if anyone has any ideas, I'm all ears.

close Excel from PowerBuilder

Working with PowerBuilder, I'm using an OLE object to make some changes in an Excel document, but when I disconnect the object, the Task Manager shown that it's still running. Also, if I open another Excel document, I can then open the Excel document that I made changes in.
I've tried just about everything I have seen on here, but most are using C# or something other than PB. The code that I've see and tried, doesn't run in PB.
Any ideas?
ole_excel = create oleobject
ole_excel.ConnectToNewObject("excel.application")
ole_excel.application.quit()
ole_excel.DisconnectObject()
In Task manager, I see the following:
EXCEL.EXE *32
Thanks,
Queue
Sometimes the process remained for whatever reason, I code a
Garbagecollect()
and the process vanishes.
Take care.
Georg

Expanding Custom Class node in Locals window silent crashes excel

The issue:
Similar to this issue but unable to find a solution I am trying to figure out how to fix this bug:
Viewing an object in Locals or Watch window causes excel to crash
The custom class is as wrapper for ADO execution allowing us to use a separate class to maintain our SQL code and execute it within the wrapper to keep error handling for MS Access ADO execution in one neat place.
This has been great for logging and debugging purposes until a few days ago I noticed trying to expand the node for the custom class in the Locals or Watch windows in the VBA editor cause Excel to silent crash after a 5 second hang and restart with the file recovery window.
Unfortunately the code is company sensitive so I may not be able to paste any in but if there are any ideas as to what might cause it I may be able to find the source and report back.
Has anyone else experienced this issue?
Update: New symptom - During debugging and comparing the text between an older build and the new one I found that the Locals window goes empty (clears of all objects) just after the hang stops and before the crash occurs.
Fixes I have tried:
Rebuilding VBA project and fixing all known compile errors (to eliminate simple vba errors)
Exporting all classes and modules - reimporting into new workbook (to eliminate the workbook file being corrupt)
Copying class and module text into notepad and clearing all formatting - pasting into new workbook (in an attempt to remove corrupt class data)
Disabling any reference to other custom classes to narrow down to a single class.
I appreciate your help and hope my issue can shed some light on it for others.
You can try below things. I hope any one of them work for you. If it still it does not works i request you to
simulate the similar issue for demo and share the code.
Possible issues with add-ins. Try to remove your addins (uninstall
the com addins) and run the code and check if you are still having
the issue.Disabling add-ins is a good test because it let you narrow
the choice of which add-in is causing the crash.
Check whether your antivirus software is up to date or is conflicting
with Excel. If your antivirus software is not up to date, Excel may
not function correctly.
Kindly run the macro on single instance of excel and check if you are
still having the issue. By single instance i mean when you go to task
manager processes tab where only one image name with excel.exe should
appear.
Verify/install the latest window updates
Try to run the same macro on other pc or other version of excel
Use mztools andin and review your code

Check if Excel workbook is open using VBScript

I have a vbs script which writes to an Excel spreadsheet. To be able to save the spreadsheet I need to ensure that it is not already open.
Can someone suggest the best way to do this?
Some research:
I tried to create a Word Tasks objects to show me all running processes, but on Windows 7 it only tells me whether Excel is running or not.
Creating an Excel.Application object does not give me access to all running instances of Excel.
I thought about opening the spreadsheet for writing but the only way I can think of doing this is with the File System Object OpenTextFile method which does not seem to be the correct approach as the Excel file is a binary.
Any other ideas?
Since the Excel.Application object doesn't give you access to all instances of Excel, what about using a simple error trap? ie. if it is unable to save the file, throw a warning message, save as another file name, etc.

Resources