Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Create a folder in system by using macro code

hi ,

how can i create   a folder in my computer, within the existed QVW file.


Thanks in advance for your replies.

Regards

Venkat

1 Solution

Accepted Solutions
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

   Create a variable which will have qvpath stores.

 

    For example Var = =QvWorkPath &'\ABC'&  

    Here ABC is a new directory name.

    And then use below macro.

     

Sub abc

set Var = ActiveDocument.GetVariable("Path")

dim filesys, newfolder, newfolderpath

newfolderpath = Var.GetContent.String

set filesys=CreateObject("Scripting.FileSystemObject")

If Not filesys.FolderExists(newfolderpath) Then

   Set newfolder = filesys.CreateFolder(newfolderpath)

   msgbox("A new folder has been created at: " & newfolderpath)

End If

End sub

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!

View solution in original post

10 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

    Here is the macro do create a folder.

   

Sub abc

dim filesys, newfolder, newfolderpath

newfolderpath = "D:\myfolder"

set filesys=CreateObject("Scripting.FileSystemObject")

If Not filesys.FolderExists(newfolderpath) Then

   Set newfolder = filesys.CreateFolder(newfolderpath)

   msgbox("A new folder has been created at: " & newfolderpath)

End If

End sub

    Make sure that you have given a full right to run macro.i.e System Access in Macro.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Not applicable
Author

Hi Kaushik,

Thanks for Reply

Instead of providing the path of folder like this i.e;  newfolderpath = "D:\myfolder"

Can we provide the path where the Current QVW exists i.e; where the current working QVW file exists there we need to provide the path.

Regards

Venkat

Not applicable
Author

Hi Kaushik,

Thanks for reply

Instead of providing the path directly i.e;  newfolderpath = "D:\myfolder"

Can we provide the path based on Current QVW file location i.e; it should create a folder where the current working QVW file is located.

Regards

Venkat

Not applicable
Author

Hi,

Here is the macro for getting the applications path.

set temp = ActiveDocument.GetApplication.GetProperties

set path = temp.ApplicationPath

Hope it helps...

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

   Create a variable which will have qvpath stores.

 

    For example Var = =QvWorkPath &'\ABC'&  

    Here ABC is a new directory name.

    And then use below macro.

     

Sub abc

set Var = ActiveDocument.GetVariable("Path")

dim filesys, newfolder, newfolderpath

newfolderpath = Var.GetContent.String

set filesys=CreateObject("Scripting.FileSystemObject")

If Not filesys.FolderExists(newfolderpath) Then

   Set newfolder = filesys.CreateFolder(newfolderpath)

   msgbox("A new folder has been created at: " & newfolderpath)

End If

End sub

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Not applicable
Author

Hi Kaushik,

Thanks, it is working in my QVW file.

Regards

Venkat

Not applicable
Author

HI Kaushik,

I got an error when i am trying to create two folders at a time. I done below procedure, pls go through with this.

NOTE: If no folder of ABC then it is generating error message. Otherwise if it contains ABC folder then it is not showing error and creating the Username folder.

For example Var = =QvWorkPath &'\ABC'&  QVUser() &'\'

    Here ABC is a new directory name. In that i am trying to create another folder with Username.

Sub abc

set Var = ActiveDocument.GetVariable("Path")

dim filesys, newfolder, newfolderpath

newfolderpath = Var.GetContent.String

set filesys=CreateObject("Scripting.FileSystemObject")

If Not filesys.FolderExists(newfolderpath) Then

   Set newfolder = filesys.CreateFolder(newfolderpath)

   msgbox("A new folder has been created at: " & newfolderpath)

End If

End sub

Regards

Venkat

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

   As you said.

   NOTE: If no folder of ABC then it is generating error message. Otherwise if it contains ABC folder then it is not showing error and creating the Username folder.

   This is right.

    If there is no Directory with name ABC then how can it create a new directory within it, and thus it is giving you an error.

    So make sure that you have ABC directory created before you run the macro.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Not applicable
Author

Hi Kaushik,

Thanks for your suggestion

I tried what you said and its working. I given macro code like below

'*****Creating Group1 Folder*****   //For Variable vGroup1Dir= =QvWorkPath &'\Group1'


Sub Group1Dir
Set Var1 = ActiveDocument.Variables("vGroup1Dir")

dim filesys, newfolder, newfolderpath
newfolderpath = Var1.GetContent.String
Set filesys = CreateObject("Scripting.FileSystemObject")

If Not filesys.FolderExists(newfolderpath) Then
Set newfolder = filesys.CreateFolder(newfolderpath)
End If
End Sub


'*****Creating Group1\User Folder*****     //For Variable vGroup1Users= =QvWorkPath&'\Group1\'&QVUser

()

Sub Group1Users
Set Var3 = ActiveDocument.Variables("vGroup1Users")

dim filesys, newfolder, newfolderpath
newfolderpath = Var3.GetContent.String
Set filesys = CreateObject("Scripting.FileSystemObject")

If Not filesys.FolderExists(newfolderpath) Then
Set newfolder = filesys.CreateFolder(newfolderpath)
msgbox("A New Folder is Created at : " &newfolderpath)
End If
End Sub


'*****Creating Group1\User\Text Folder*****
Sub TabDelimitedTextGroup1                                   
    set v1 = Activedocument.Variables("vGroup1Users")
    set obj1 = ActiveDocument.GetSheetObject("CH46")    
    obj1.Export   v1.GetContent.String &"\"  &Date()&"_"&replace(Time(),":","")&".txt",","
    MsgBox("Data Has Been Transfered")
End Sub

Regards

Venkat