Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
johnan
Creator III
Creator III

Reload with batfile and macro

Hi , i have a macro that export images, when i run this in the qlikview with a button it works perfect.

When i run this with a batfile, it's reloading the qv but the last thing happend is that the macrowindows stays open and nothing more happens.

Batfile:
"C:\Program Files\QlikView\Qv.exe" /l /NoSecurity "C:\Qv\MXXX.qvw"
Macro:

function exportImages
' Test if export should be made
set v = ActiveDocument.Variables("RunNow")
if v.GetContent.String = "Yes" then
v.SetContent "No",true
exportAll
ActiveDocument.GetApplication.Quit
end if
end function

function exportAll
export("CH01")
export ("TX01")
end function

function export(chartId)
set obj = ActiveDocument.GetSheetObject(chartId)
obj.ExportBitmapToFile "C:\UTL\Chart_" & chartId & ".png"
end function

 

What can i do to get this working?

Br

1 Solution

Accepted Solutions
marcus_sommer

It shouldn't - the batch creates a new instance and QV quit it again. It should work in this way.

By testing such things you need further ensure that no other instance has opened the same file and/or that further files are opened within the instance - to avoid the classical windows popup's if you want to overwrite this file or store the other or similar things because these popup's are there but won't be displayed in any way.

- Marcus

View solution in original post

39 Replies
marcus_sommer

Try it in this way:

sub exportImages
' Test if export should be made
set v = ActiveDocument.Variables("RunNow")
if v.GetContent.String = "Yes" then
v.SetContent "No",true
call exportAll
ActiveDocument.GetApplication.Quit
end if
end sub

sub exportAll
call export("CH01")
ActiveDocument.GetApplication.Sleep 1000
call export ("TX01")
end sub

sub export(chartId)
set obj = ActiveDocument.GetSheetObject(chartId)
obj.restore
ActiveDocument.GetApplication.WaitForIdle
obj.ExportBitmapToFile "C:\UTL\Chart_" & chartId & ".bmp"
end sub

The grey statements are optional - especially in larger export-routines they are necessary to ensure a stable workflow.

- Marcus

johnan
Creator III
Creator III
Author

Okay, i will try. 

To call the macro is exportAll?

marcus_sommer

Yes, exportAll - the essential point is the switch from a function to a sub because a function couldn't be "called" and it expect a return-value. The call itself is optional but it improved the readability.

- Marcus

johnan
Creator III
Creator III
Author

It's the same, it will open the macromodule at the end 😞

And it works when i open it manually and press the button

Something else that i missing?

jaibau1993
Partner - Creator III
Partner - Creator III

Hi!

Can you please share a screenshot of the macro module when it opens when you run it from the bat file, please?

Jaime.

johnan
Creator III
Creator III
Author

Yes, here you go!

 
 
 
 

SkärmklipQV.PNG

marcus_sommer

What do you mean with?

"... And it works when i open it manually and press the button ..."

Right click on the object and exporting it, executing it within the module-editor, from the UI per button/action, from the outside per EXECUTE or windows task, ...?

- Marcus

 

johnan
Creator III
Creator III
Author

I have a button on the QV application. In that button i have call run Macro -> exportAll. 

So if i open the QV  manually and press that button it's work.

If i run the batfile, after the reload it's just open the Macrowindow and nothing happens. 

jaibau1993
Partner - Creator III
Partner - Creator III

Quite weird, can not reproduce your problem.

Got to ask: have you configured a trigger "on open" as in the following image?

Settings.png

 

BTW, shouldm't you call "exportImages" instead of "exportAll"?

On the other hand, when the macro is run from the bat file, is it run with a user with writting permissions in "C:\UTL\"?

Regards,

Jaime.