Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Using relative path in macro

What I am trying to achieve:

I created a button that will allow me to export activated charts to a folder. So i name this folder Exports and use relative paths for convenience sake because I intend to put it on server.

What i tried:

There is no issue exporting it using the absolute path that has been commented out below.

What i know:

the syntax "..\" basically goes one folder higher.

Current Dashboard path:

C:\Users\muzamirnasir\Desktop\ACGME-I Survey\Dashboard

Problem:

I cannot seem to get the relative path to work.Nothing is exported, even if it is wrong, the file should still be somewhere. It seems to work for "STORE" on another dashboard.

What did i miss out? Is there a way out of this? Any examples? Is it ExportBitMapToFile?

I currently coded this out on Macro..

'Export for Details tab

SUB SaveBitmapDetails

'SET obj = ActiveDocument.GetSheetObject("CH87")

'obj.ExportBitmapToFile "C:\Users\muzamirnasir\Desktop\ACGME-I Survey\Exports\CH87.jpg"

SET obj = ActiveDocument.GetSheetObject("CH75")

obj.ExportBitmapToFile "..\..\Exports\CH75.jpg"

END SUB

7 Replies
marcus_sommer

It is not possible to use relative paths within vbscript directly - you will need to build an own logic, see here various approaches to get it: https://www.google.de/search?q=vbscript+relative+path

- Marcus

rubenmarin

Hi Muzamir, there is a property of the document with the path, maybe you can work with that:

set docprop = ActiveDocument.GetProperties

msgbox(docprop.FileName)

It will return path and filename of the document.

Not applicable
Author

I am sure it will come in handy but i still need the relative path. Currently, im just using an absolute path which can inefficient.

Not applicable
Author

Almost there.

set mypath = ActiveDocument.GetProperties
' Has no "\" at the end
curDir = mypath.MyWorkingDirectory
msgbox(curDir)
relativeDir = curDir & "\..\ThisDirIsRelative"
msgbox(relativeDir)
Not applicable
Author

Using relative paths in VBScript works in my QV 11.20 installation, but not in QV 12.0.

I tested a little using the following VBScript function:

Function VBWorkingDir

  Dim fso

  Set fso = CreateObject("Scripting.FileSystemObject")

  VBWorkingDir = fso.GetAbsolutePathName(".")

End Function

This function returns my application(qvw) directory in 11.20, but in 12.0 it returns "D:\Program Files\QlikView"

As I use my VBScript function in the QV load script to initialize variables, performance doesn't matter and I can expand relative paths like this:

FOR EACH v.Logfile IN filelist ( '..\logdir\myapp.log' );

NEXT v.Logfile // EmptyFOR EACH loop to convert relative filename to full path

Not applicable
Author

A workaround is to use a function to set the working directory of the VBScript engine:

' VBScript:

On Error Resume Next    ' Should go to the top of your script

Function VBSetWorkingDir(dirPath)

  Dim objShell

  Set objShell = CreateObject("Wscript.Shell")

  objShell.CurrentDirectory = dirPath

  VBSetWorkingDir = Err.Description

End Function


// QlikView Script:

LET v.ErrorMsg = VBSetWorkingDir(Text(QvWorkPath));

Further comment

If I knew how to access QvWorkPath from VBScript I could have put the code in the initialization part of VBScript, then you would not need to call any function before using relative paths.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Hans,

Are you wanting to use the QvWorkPath during reload or from the UI? A caution on QvWorkPath: QvWorkPath is set at the end of script execution. The QvWorkPath you get during reload is from the last execution. If you move a file, QvWorkPath will not be correct in the first reload.

-Rob

http://masterssummit.com

http://qlikviewcookbook.com