Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

haribabugv
Contributor

OSUser in Macro file path

Hello users,

I am trying to open a file using a macro and then executing it.

I am getting error when i try below script.

 

I have defined vUserName  =subfield(OSUser(),'\',2) in variable settings.

set v = ActiveDocument.Variables("vUserName") 
vUserName = v.GetContent.String 
filepath="C:\Users\("&vUserName&")\Documents\Sample.qvw"

is there anything wrong in the above script? can you please correct it and share the correct code

 

Thanks

 

Labels (2)
1 Solution

Accepted Solutions

Re: OSUser in Macro file path

Can you try this.?

set v = ActiveDocument.Variables("vUserName")
vUser = v.GetContent.String
filepath="C:\Users\"&vUser&"\Documents\Sample.qvw"
3 Replies

Re: OSUser in Macro file path

Can you try this.?

set v = ActiveDocument.Variables("vUserName")
vUser = v.GetContent.String
filepath="C:\Users\"&vUser&"\Documents\Sample.qvw"
haribabugv
Contributor

Re: OSUser in Macro file path

Hello Settu

Thanks, I will check your solution in a while.

What if there are spaces in my file path as shown below?

set v = ActiveDocument.Variables("vUserName")
vUser = v.GetContent.String
filepath="C:\Users\"&vUser&"\Documents\New Documents\Sample.qvw"

Can you please provide alternate to the above script where i can consider spaces in the file path defined above?

Highlighted
schernov
New Contributor III

Re: OSUser in Macro file path

try

SUB test1()
	set v = ActiveDocument.Variables("vUserName")
	vUser = v.GetContent.String
	filepath="C:\Users\"&vUser&"\Documents\New Documents\Sample.qvw"
	'msgbox filepath
	
	' for tests:
	qvpath = "C:\Program Files\QlikView\qv.exe"
	filepath = "d:\Qlik\Dev\30_QvdGenerators\model_oos.qvw"
	
	' use chr(34)
	Set shell = CreateObject("WScript.Shell")
	shell.Run chr(34) & qvpath & chr(34) & " " & chr(34) & filepath &  chr(34)
	
END SUB