Solved

Replacement for 'UserAccounts.CommonDialog'

Posted on 2014-03-04
3
755 Views
Last Modified: 2014-03-04
We have discovered that VB scripts written for XP using 'UserAccounts.CommonDialog' (which enables the user to browse to a file, and returns a text string containing the name of the file) do not work in Windows 7.  I have spent an inordinate amount of time researching a replacement.  What I have found is myriad solutions that get shut down by new MS security enhancements, or have limitations regarding the kind of file that one can select, or limitations relating to the return of the file name only, and not the full path.

RobSampson provided a great solution on 4/4/2013 that can be found on EE under the title "Windows 7 CommonDialog class at:
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/Windows_7/Q_28070742.html#a39049827

I have modified it so that it runs in our scripting environment, including allowing the user to select All Files *.*

What I cannot figure out is how to specify the starting path location for the search.  The key line is:

tempFile.WriteLine("    s = Dlg.openfiledlg(, , CStr(" & strDQ & "Microsoft Word(*.doc;*.docx)|*.doc;*.docx|Microsoft Excel(*.xls;*.xlsx)|*.xls;*.xlsx|Adobe PDF(*.pdf)|*.pdf|" & strDQ & "), CStr(" & strDQ & "Choose File" & strDQ & "))")

If I am correct, that .openfiledlg method is defined at MS page:
http://msdn.microsoft.com/en-us/library/aa769135(v=vs.85).aspx
and if that reference is correct, the second argument, which is blank in the above line of code, is the initial directory:
HRESULT openfiledlg(
    VARIANT initFile,
    VARIANT initDir,
    VARIANT filter,
    VARIANT title,
    BSTR *pathName
);
Parameters
initFile [in] VARIANT of type VT_BSTR that contains the initial file name to open.
initDir [in] VARIANT of type VT_BSTR that contains the initial directory to open.

When I look at the other arguments that Rob has successfully placed in that openfiledlg call, such as the 'title' argument, I do not recognize
his syntax:  CStr(" & strDQ & "Choose File" & strDQ & ")
which does not look like other instances I have seen:   ie. simply "c:\"

I have tried and failed testing every variation I can think of in order to set that second argument called initDir, including such things as
      "c:\data"
      CStr("c:\data")
      CStr(" & strDQ & CStr("c:\data") & strDQ & ")
      CStr(" & strDQ & CStr("c:\data\") & strDQ & ")
      CStr(" & strDQ & CStr("c:\\data") & strDQ & ")
      CStr(" & strDQ & CStr("c:\\data\\") & strDQ & ")
      CStr(" & strDQ & CStr("c:\\data") & strDQ & ")
      CStr(" & strDQ & CStr(""c:\\data"") & strDQ & ")
      CStr(" & strDQ & CStr(""c:\\data\\"") & strDQ & ")

Does anybody have any suggestions here?
0
Comment
Question by:miketonneson
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39904789
If you look a little bit lower in that thread, you will see the syntax for opening c:\temp, for ex, is:
 tempFile.WriteLine("    s = Dlg.openfiledlg(CStr(" & strDQ & "C:\Temp\*" & strDQ & "), , CStr(" & strDQ & "Microsoft Word(*.doc;*.docx)|*.doc;*.docx|Microsoft Excel(*.xls;*.xlsx)|*.xls;*.xlsx|Adobe PDF(*.pdf)|*.pdf|" & strDQ & "), CStr(" & strDQ & "Choose File" & strDQ & "))")

Open in new window


HTH,
Dan
0
 

Author Closing Comment

by:miketonneson
ID: 39904902
That works.  Thanks so much.
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39904920
Glad I could help. It's not my solution, I just read a bit further :)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now