# VB Script and Scheduled Task



## shanejvv (Jan 17, 2011)

Hello, 

1st post on TSF! Yay for me! Anyways, I have a vbs file that opens a Qlikview document, maximizes the window, reloads the document so that the data is up to date and then exports the images as jpegs. The thing is that when I'm logged in, the process runs smoothly via a scheduled task but when I'm logged out, everything except the maximize window command seems to work. 

When I'm logged out from the server where everything resides, the result is that the document opens, processes and exports the images but the images are not maximized which cuts parts of it off. 

The VB Script file has the following:

***********************************************

Set MyApp = CreateObject("QlikTech.QlikView")
Set MyDoc = MyApp.OpenDoc ("C:\Qlikview\Help Desk Monitoring\Current HD Stats\Current Helpdesk Stats.qvw")

Set ActiveDocument = MyDoc

Set Shell = WScript.CreateObject("WScript.Shell")
shell.sendkeys "(% )X"

ActiveDocument.GetApplication.WaitForIdle

ActiveDocument.Reload
ActiveDocument.Save

GraphPath = "C:\Qlikview\Help Desk Monitoring\Current HD Stats\Current_HD_Images\"
GraphPath2 = "C:\Dashboards\current\"

ActiveDocument.Sheets("Current Dashboard").Activate
ActiveDocument.GetApplication.WaitForIdle
ActiveDocument.Sheets("Current Dashboard").ExportBitmapToFile GraphPath & "Current Dashboard.jpg"
ActiveDocument.Sheets("Current Dashboard").ExportBitmapToFile GraphPath2 & "Current Dashboard.jpg"
ActiveDocument.ClearCache

ActiveDocument.GetApplication.Quit

***********************************************

I've checked that the scheduled task is set up right, it's only when I'm logged out that the Shell.Sendkeys command doesn't seem to execute.

I'll appreciate any and all help.

Thanks,
Shane


----------



## TheOutcaste (Mar 19, 2009)

If you are not logged on, there is no GUI for sendkeys to send keys to, so I don't think that will work.

Don't know if QlikView supports it, but might try this:


```
Const WindowStateMaximized = 1

ActiveDocument.ActiveWindow.WindowState = WindowStateMaximized
```
Add the WindowState line after you activate the window.


----------



## shanejvv (Jan 17, 2011)

Hi,

thanks for the reply. What you're saying makes a lot of sense. I tried replacing the sendkeys command but it keeps giving me an error:

Object doesn't support this proeprty or method: 'ActiveDocument.Sheets(...).Maximize'
Code 800A01B6

I've also tried - - - ActiveDocument.Sheets("Current Dashboard").Maximize

No result there.

Is there anything else I can try?

Thanks for your response
Shane


----------



## TheOutcaste (Mar 19, 2009)

Did you add the exact lines from above?
That section of code will then look like this:

```
GraphPath = "C:\Qlikview\Help Desk Monitoring\Current HD Stats\Current_HD_Images\"
GraphPath2 = "C:\Dashboards\current\"

[COLOR=Red]Const WindowStateMaximized = 1[/COLOR]

ActiveDocument.Sheets("Current Dashboard").Activate
[COLOR=Red]ActiveDocument.ActiveWindow.WindowState = WindowStateMaximized[/COLOR]
ActiveDocument.GetApplication.WaitForIdle
```


----------



## shanejvv (Jan 17, 2011)

Hi,

I think I may have inserted your solution incorrectly the first time. It still isn't going through but the reason is narrowed down to the line:

ActiveDocument.ActiveWindow.WindowState = WindowStateMaximized

The reason I say this is because the error is:

Object doesn't support this property or method: 'ActiveDocument.ActiveWindow'

Is there any other method I can try?


----------



## TheOutcaste (Mar 19, 2009)

You'd have to track down the reference for the Qlikview program to see what methods it does support. It may not have a way to maximize the window, or it may be as simple as just ActiveDocument.Maximize, or there may be a variable you can set using ActiveDocument.Variables("VariableName").SetContent.

I haven't found a reference, just snippets of code.

One thought, if you maximize the window before closing the program, does it open maximized the next time?
If not, does it save it's size and position? If it does, you can size the window to fill the screen, but not actually maximize it, that might work.


----------



## shanejvv (Jan 17, 2011)

Hello Outcaste,

Sorry for the HUGE delay in reply but I just wanted to thank you for your advice which sent me on the right path to getting my scrip to execute properly with the shell.sendkeys command. 

The fix was to place the document with the script on a PC that we use to display stats where the Administrator account is always logged in. I VNC in to make any necessary changes but because there's a GUI running behind the slideshow that the PC displays, it works 100%. 

I export the image to a different file location on the network and it's been working fine.

Thanks once again,
Shane


----------

