Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro Object Export.

Does anyone know if we can use relative paths for theobject export.  Right now I am using obj.Export

"Z:\Documents\CheggSVN\EDW\reporting\trunk\qlikview\"&object_id&".csv",","

But anything I change it to like obj.Export ""&object_id&".csv",","  or obj.Export "../qlikview/"&object_id&".csv",","  all give me an error cannot open file for writing.  Even if it is in the exact location as the hard coded path.  I just want to make this relative so we can deploy it to different environemnts and know the structure will be there.  This full absolute path is brittle.   

1 Solution

Accepted Solutions
flipside
Partner - Specialist II
Partner - Specialist II

I usually set up some global variables along the lines of the following.  The key is to set the current working directory using .MyWorkingDirectory, then navigate up the filepath using the InStrRev function.  Test this sample macro.

sub CurrentDir
Dim docProp
set docProp = ActiveDocument.GetProperties

Dim tmpFile  'used to create relative filepaths
tmpFile = docProp.MyWorkingDirectory
msgbox tmpFile

Dim vSpl  'location of final backslash char
vSpl = InStrRev(tmpFile,"\")
msgbox vSpl

tmpFile = Left(tmpFile,vSpl) & "QVOutputData\example.txt"      'file will be written one folder up, then two down
msgbox tmpFile

end sub

flipside

View solution in original post

4 Replies
Not applicable
Author

have you tried with backslashes?

Not applicable
Author

Yeah and with no slashes just trying to drop it in the root dir but same error.  I have to hard code the full path from the drive letter forward. 

flipside
Partner - Specialist II
Partner - Specialist II

I usually set up some global variables along the lines of the following.  The key is to set the current working directory using .MyWorkingDirectory, then navigate up the filepath using the InStrRev function.  Test this sample macro.

sub CurrentDir
Dim docProp
set docProp = ActiveDocument.GetProperties

Dim tmpFile  'used to create relative filepaths
tmpFile = docProp.MyWorkingDirectory
msgbox tmpFile

Dim vSpl  'location of final backslash char
vSpl = InStrRev(tmpFile,"\")
msgbox vSpl

tmpFile = Left(tmpFile,vSpl) & "QVOutputData\example.txt"      'file will be written one folder up, then two down
msgbox tmpFile

end sub

flipside

Not applicable
Author

wow, that was much harder than it ever needed to be for a relative path .   But it worked. 

Thanks