Link to home
Start Free TrialLog in
Avatar of miketonneson
miketonneson

asked on

Replacement for 'UserAccounts.CommonDialog'

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:
https://www.experts-exchange.com/questions/28070742/Windows-7-CommonDialog-class.html?anchorAnswerId=39049827#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?
ASKER CERTIFIED SOLUTION
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of miketonneson
miketonneson

ASKER

That works.  Thanks so much.
Glad I could help. It's not my solution, I just read a bit further :)