Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
Here is below the code I use to take a screenshot of an application. I managed to close the app but I don't find a way to close Qlikview.
set Qv = CreateObject("QlikTech.QlikView")
Set QvDoc = Qv.OpenDoc ("D:\…\Application.qvw","","")
QvDoc.GetApplication.WaitForIdle
QvDoc.Sheets("Sheet Name").ExportBitmapToFile "D:\…\Screenshot.jpg"
QvDoc.CloseDoc()
QvDoc.GetApplication.Quit closes the software but it generates a popup saying that Qlikview has stopped working.
Killing the process on the server seems too brutal for me.
Thank you for your help.
I don't have enough knowledge to find a perfect process and there are limitations from my external scheduler (not QMC).
I finally found this solution:
1. Duplicate the application and insert these macros when the document is open (OnOpen trigger):
Sub AutoReload
ActiveDocument.Reload
ActiveDocument.Save
End Sub
sub export
ActiveDocument.GetApplication.WaitforIdle
ActiveDocument.ActiveSheet.ExportBitmapToFile "D:\QLIKVIEW\…latest_screenshot.jpg"
ActiveDocument.GetApplication.Sleep 1000
ActiveDocument.GetApplication.Quit
End sub
2. Create a small cmd to open the application:
start "" "D:\QLIKVIEW\…\Application.qvw"
The application and the Qlikview client are properly closed.
This duplicate application is of course reloaded before this process.
Thank you again for your time.
Note: well I hope it's the final solution for my needs 🙂
Try it with: Qv.GetApplication.Quit
- Marcus
I get this error:
Ok. then try it without closing the document:
set Qv = CreateObject("QlikTech.QlikView")
Set QvDoc = Qv.OpenDoc ("D:\…\Application.qvw","","")
QvDoc.GetApplication.WaitForIdle
QvDoc.Sheets("Sheet Name").ExportBitmapToFile "D:\…\Screenshot.jpg"
QvDoc.GetApplication.Quit
- Marcus
Everything is closed but I also get this popup
That's a Windows message and means that QlikView isn't terminated yet else it's running and doesn't communicates properly with the OS. I'm not absolutely sure but if I look on the example from the APIGuide.qvw it seems that there is no document is initialized which is usually needed as basis for many statements. Therefore try it with such a statement, like:
set QvInst = CreateObject("QlikTech.QlikView")
Set QvApp = QvInst.OpenDoc ("D:\…\Application.qvw","","")
Set QvDoc = QvApp.ActiveDocument
QvDoc.GetApplication.WaitForIdle
QvDoc.Sheets("Sheet Name").ExportBitmapToFile "D:\…\Screenshot.jpg"
QvDoc.CloseDoc
QvDoc.GetApplication.Quit
- Marcus
Thanks again for your help.
There's an error with this new statement.
Try it with a replace from:
Set QvDoc = QvApp.ActiveDocument
to
Set QvDoc = ActiveDocument
- Marcus
Forget it... I have to find another way to generate a screenshot of the application. My scheduler doesn't work well with the vbs script.
I'll try with PowerShell or I'll see if it's doable to generate a pdf file every 2 hours...
To automate such a task is definitely not trivial and there are a lot of possibilities what might go wrong without returning helpful error-messages to find the real cause which often leads to ways to solve or at least to bypass the challenge. Here the way which we use:
- QMC - task within a task-chain with an EXECUTE statement
- EXECUTE triggers a Windows-task
- Windows-task starts with a command-line statement - with the parameter /l - the QV desktop client with a
certain control application
- control application performed a reload
- reload triggers a macro
- macro runs within loops through multiple UI tables containing paths + app + various other information
and opened the appropriate apps and performed prints + exports + storing/mailing the stuff
- if everything is done - it called a close and quit statement
I don't know how your process look like but one bigger difference is that you calls an external vbs and we open a control app with the desktop client and using vbs on the inside from QV. IMO the approach using a control app which reads all relevant information in tables and performed within loops multiple actions is much more flexible as using single batch-files.
For us it worked fine and the above mentioned process is totally automated. But it requires to adjust multiple settings within the user + document settings as well as on the server, distribution engine and Windows (task-planner, local policies). Therefore it could become quite hard to get it to work within the mentioned way.
I'm not sure if another tool like PowerShell could make it easier. If your approach creates the expected output and isn't just closing afterwards you may consider to kill this process with another batch (whereby I assume it's rather a quite small syntax issue which prevents to quit QV properly). If max. one QV.exe is running it's not extremely complicated but if there are running multiple instances you would find a way to detect the right one …
- Marcus