Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
haribabugv
Creator
Creator

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
settu_periasamy
Master III
Master III

Can you try this.?

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

View solution in original post

3 Replies
settu_periasamy
Master III
Master III

Can you try this.?

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

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?

Chernov
Creator
Creator

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