Solved

How can vba process name and path of user selected files and folders

Posted on 2003-12-10
3
553 Views
Last Modified: 2008-02-01
For now, I only want to print the full path name of the object. Later I will add many other functions

I’ve had very little luck in my research, although getopenfilename is a little like what I want, as is a routine named WordApplicationGetOpenFileName (http://www.erlandsendata.no).

My ideal vba program would present the user with an internet explorer dialog box that lets the user browse and click to select individual files to be renamed.  The user would be able to do a scattered selection by using ctrl click.  The dialog would also have an OK/Cancel button.

For instance, if the folder structure looks like this:

Lvl1Fldra
   Lvl2FldrB   < Selected by user
      Lvl3File3-1.xls  
      Lvl3File3-2 .doc  
   Lvl2FldrC  

   Lvl2File2-1.xls < Selected  by user
   Lvl2File2-2.xls
   Lvl2File2-3.xls < Selected  by user

The vba program would print
   Selection 1 is a folder named: c:\Lvl1Fldra\lvl2FldrB
   Selection 2 is a file named: c:\Lvl1Fldra\lvl2file2-1.xls
   Selection 3 is a file named: c:\Lvl1Fldra\lvl2-3.xls
 


The vba program might be something like this pseudo code
    dim usrSel as SelectionSet
    dim ct as integer
    set usrSel = myMagicDialogFunction("Select your folders",myVbReturnCode)
    if myvbReturnCode = vbOK then
       for each obj in usrSel
           ct = ct +1
           if obj.type is a folder then
               debug.print  "selection “ & ct & “is a folder named “ & obj.name
           else
               debug.print  "selection “ & ct & “is a file named “ & obj.name
           endif
       next obj
    endif
     

An even better approach would be to add it as a function directly to Windows Explorer, perhaps as a sendto function.  I would select the files and folders, right click on the selection, then execute the program.
0
Comment
Question by:rberke
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
PurplePerls earned 500 total points
ID: 9916215
You are right, the Explorer alread implements your myMagicDialogFunction() functionality.
So is the only the question how to use it?

Ok, store this script as list.vbs in the folder C:\DocumentsAndSettings\YourUserId\SendTo\list.vbs

Set objArgs = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
ct = 0
For I = 0 to objArgs.Count - 1
   DirFile = objArgs(I)
   ct = ct +1
   If (fso.FolderExists(DirFile)) Then
     msg = "Selection " & ct & " is a Folder: " & DirFile
   Else
     msg = "Selection " & ct & " is a File: " & DirFile
   End If
   WScript.Echo msg
Next



Give it a try.

Good luck,
PurplePerls

0
 
LVL 5

Author Comment

by:rberke
ID: 9917319
That code is very near to my goal, and is worthy of most of the points.

The only problem is that I want to use VBA inside of Excel, because I want to do lots of other processing on the objects. Many of the processes will use subroutines that I have already written in VBA.

How can I create an Excel workbook with a WorkbookOpen subroutine that does the same thing? I tried putting a TEST.xls workbook into my SendTo folder, but it does not appear on the when click on the Explorer SendTo submenu.
0
 
LVL 5

Author Comment

by:rberke
ID: 9940944
I'm giving you the full points, but I would still like suggestions on how to use VBA instead of VBS.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Validating VB6 Function 19 59
how can i unlock a picture file that was loaded in a picturebox in visual c#? 4 93
passing parameter in sql procedure 9 61
Adding to a VBA? 6 70
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 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