Solved

Replacement for 'UserAccounts.CommonDialog'

Posted on 2014-03-04
3
839 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

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 35

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
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.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

624 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