Qlik Community

Ask a Question

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Talk to Experts Tuesday, January 26th at 10AM EST: Qlik Sense. REGISTER NOW
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Declaring Variables in VBScript

Hi all,

This is driving me crazy...... I wish to set a variable in VBScript but it's not working.

This is my code....

I am creating a number of folders and I wish to set each folder path as a variable:

' set ocr path

SUB Ocr (objVariable)


  SET objShell = CREATEOBJECT("Shell.Application")

  SET objFolder = objShell.BrowseForFolder (WINDOW_HANDLE, TITLE, OPTIONS, ROOT)

  SET objFolderItem = objFolder.Self

  ocrFolder = objFolderItem.Path

  SET objSavePath = ActiveDocument.Variables(objVariable)

  objSavePath.SetContent ocrFolder, TRUE


'create folders

Dim oFSO

Set oFSO = CreateObject("Scripting.FileSystemObject")

' Create OCR folder

oFSO.CreateFolder ocrFolder & "\OCR"

oFSO.CreateFolder ocrFolder & "\OCR\Output"

oFSO.CreateFolder ocrFolder & "\OCR\Output\Single_File"

oFSO.CreateFolder ocrFolder & "\OCR\Staging"

oFSO.CreateFolder ocrFolder & "\OCR\Archive"

dim outputFolder

outputFolder = ocrFolder & "\OCR\Output\Single_File"

dim stagingFolder

stagingFolder = ocrFolder & "\OCR\Staging"

dim archiveFolder

archiveFolder = ocrFolder & "\OCR\Archive"

end sub

ocrFolder is defined (e.g. c:mydocs\myfolder)

My issue is that outputFolder , stagingFolder & archiveFolder  are not being created?

What am I doing wrong? 

5 Replies
MVP & Luminary
MVP & Luminary

The reason could be the use of relative paths. For this topic see also: Using relative paths in variables.

- Marcus

Creator III
Creator III

Haven't tested but what happens if you try setting the oFSO.CreateFolder commands to a variable and call it directly?


'create folders

Dim oFSO

Set oFSO = CreateObject("Scripting.FileSystemObject")

' Create OCR folder

set f1 = oFSO.CreateFolder ocrFolder & "\OCR"

set f2 = oFSO.CreateFolder ocrFolder & "\OCR\Output"

set f3 = oFSO.CreateFolder ocrFolder & "\OCR\Output\Single_File"

set f4 = oFSO.CreateFolder ocrFolder & "\OCR\Staging"

set f5 = oFSO.CreateFolder ocrFolder & "\OCR\Archive"

CreateFolderF1 = f1.Path

CreateFolderF2 = f2.Path

CreateFolderF3 = f3.Path

CreateFolderF4 = f4.Path

CreateFolderF5 = f5.Path

Not applicable

Thanks for the replies - I couldn't get it to work.

So I just had to use the variable + 'the end folder path (hard coded)', throughout my code.

Not applicable

Hi Jammy,

From the script it looks like you are using "BrowseForFolder " which will give you a pop up to select the path. If you cancel that pop up it will create folders in default location may be in "C:" or "C:\Program Files\QlikView".

You can check the above mentioned folders, all the folders which you were creating using macro must have been created somewhere in your machine.

PS: As per your script, ocrFolder is nothing but a variable which is already appended before the folder path, I am not sure why are you adding another variable.

Hope it helps.



MVP & Luminary
MVP & Luminary

Like in my link from above the logic could be like relative paths even if the in the end used path is a full-path (and therefore is no need to hard-code the paths).

- Marcus