Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I have a vbscript which performs the action of reducing data(File - > Reduce Data -> Select Possible).
Set MyApp = CreateObject("QlikTech.QlikView")
Set MyDoc = MyApp.OpenDocEx(vFilePath,0,False)
MyDoc.ReduceData
MyDoc.SaveAs(vFilePath)
MyDoc.CloseDoc
Set MyApp = Nothing
vFilePath contains the absolute file path of the qvw to be reduced. The issue here is the above code does not work when relative paths are used in vFilePath whereas it works perfectly fine for absolute paths.
Can anyone please help me with the same.
Thanks,
Asma
I have had now a look on google to relative paths within vbs and it seems that there is no native way to execute them. What I have found are various kinds of workarounds to generate a fullpath and here is one possible solution adapted to qlikview:
sub Test
dim vTest, vFolderCount
vTest= "\applications other\calendar4-5-4.qvw"
vFolderCount = len(vTest) - len(replace(vTest, "\", ""))
vTest = ActiveDocument.evaluate("left(DocumentPath(), index(DocumentPath(), '\', " & -vFolderCount & ") - 1)") & vTest
msgbox vTest
call ReduceData(vTest)
end sub
- Marcus
AFAIK relative paths do work in vbs. Therefore I think that your relative path isn't correct and/or the syntax isn't right and you might need additionally double-quotes around the path.
- Marcus
Hi Marcus,
The folder structure is as shown below:
The Qlikview file containing the macro code for reducing data is present in folder B.
The folder Application contains the qvw file to be reduced.
In the vbscript, I have given the relative path as:
dim vTest
vTest= "..\A\ABC\Application\Reduce_data.qvw"
If I use the absolute path in the code, then it runs fine without giving any error. Whereas if relative path Is given, it throws an error as Object required : 'MyDoc' at the line "MyDoc.ReduceData"
VBscript code:
Function ReduceData(vFilePath)
Set MyApp = CreateObject("QlikTech.QlikView")
Set MyDoc = MyApp.OpenDocEx(vFilePath,0,False)
MyDoc.ReduceData
MyDoc.SaveAs(vFilePath)
MyDoc.CloseDoc
Set MyApp = Nothing
end Function
'ITP Dashboard
sub Test
dim vTest
vTest= "..\A\ABC\Application\Reduce_data.qvw"
call ReduceData(vTest)
end sub
Could you please help me with the same.
Thanks,
Asma
I have had now a look on google to relative paths within vbs and it seems that there is no native way to execute them. What I have found are various kinds of workarounds to generate a fullpath and here is one possible solution adapted to qlikview:
sub Test
dim vTest, vFolderCount
vTest= "\applications other\calendar4-5-4.qvw"
vFolderCount = len(vTest) - len(replace(vTest, "\", ""))
vTest = ActiveDocument.evaluate("left(DocumentPath(), index(DocumentPath(), '\', " & -vFolderCount & ") - 1)") & vTest
msgbox vTest
call ReduceData(vTest)
end sub
- Marcus
Thanks Marcus for the quick reply!
The VB Code is working as expected.
I just need a small clarification. Could you please explain what does the below line of code mean:
vTest = ActiveDocument.evaluate("left(DocumentPath(), index(DocumentPath(), '\', " & -vFolderCount & ") - 1)") & vTest
Thanks,
Asma
The logic is to read the full-path from the current script and cut the right-part to the x-number of backslashes (counted before in vFolderCount) and then adding the used relative-part which is then together a valid full-path again.
The backslash-counting is done here in vbs because it's quite simple with len + replace. To cut a string to a variable point isn't so easy in vbs and therefore it's done with qlikview-functions called per evaluate().
- Marcus
Thanks Marcus!!