Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Save $600 on Qlik Connect registration! Sign up by Dec. 6 to get an extra $100 off with code CYBERSAVE: REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

When exporting to a text file how do I let the user select their own save path?

Hi all,

The code below Exports table content to a text file. Does anyone know how I do the following:

a) default the save path to the current user's desktop?

b) pop a file dialog box for the user to choose the save path?


set obj = ActiveDocument.GetSheetObject("CH804")

obj.ExportEx "C:\Users\John\Desktop\test.txt", 1


Thanks,

John.

7 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


Peter Rieper wrote:http://community.qlik.com/media/p/79850.aspx, which uses File-Dialogue


Be warned that the File Dialogue in this app uses "UserAccounts.CommonDialog", which is only available in Win XP. If you are using any other flavor of Windows (Vista, 2x, 7) the File Dialog will not work.

-Rob

prieper
Master II
Master II

@Rob: Good point - Thanks.

Is there better way rather than using then an inputbox, which might work on different platforms?

Peter

Anonymous
Not applicable
Author

Hi Rob and Peter,

thank you for comments so far. Leveraging off Peter's last comment, an alternative (for me) would be to save the output to the user's desktop.

So, if there was an environment variable that tells me the desktop path this would suffice in place of the file dialog. It might still come down to the same problem mentioned by Rob, this being the different engine used from XP to the newer builds of windows.

This has given me something else to research on the net.

thanks, and be sure to comment here if you know that all important code snippet that will reveal the user's desktop path. Smile

thank you,

John.

prieper
Master II
Master II

I am not that expert, but seems that user's desktop is available under C:\Documents and Settings\NT-Name\Desktop, thus you only need to construct a string like

LET sPath = 'C:\Documents and Settings\' & SUBFIELD(OSUSER(), '\', 2) & '\Desktop';


HTH
Peter

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


Peter Rieper wrote:LET sPath = 'C:\Documents and Settings\' & SUBFIELD(OSUSER(), '\', 2) & '\Desktop';


In Vista it's "users\" instead of "Documents and Settings".

I think the environment variable that is common across Windows versions is "USERPROFILE". You can get the env variable in the script with something like: http://windowsitpro.com/article/articleid/84803/jsi-tip-9956-how-do-i-use-an-environment-variable-in-vbscript.html

There are also a number of hacks to be found on the web where people use a file chooser dialog from MS Office, IE or Shell. Google and you'll find them. Attached is a sample that tries to use UserAccounts.CommonDialog and then falls back to Excel if CommonDialog is not found.

In CommonDialog, you can use the env variable %USRPROFILE%. I'm not sure how to do that in the Excel dialog. Maybe oXL.ChDir or oXL.SetCurrentDirectory would accept the %% syntax. I can't try it because I don't have Excel on this machine.

Seems worth asking if you've considered the simpler (for you) solution of having the user right-click the chart and use the Export option?

Have fun and let us know if you develop the killer solution.

-Rob

rbecher
MVP
MVP

Thanx Rob, I will use this for my QVDViewer on Vista+.

- Ralf

Astrato.io Head of R&D
Not applicable
Author

Hi,

Theses solutions are interesting, but this is how to select a file, isn'it ?
Is there any way to select a folder ?

Best regards