Solved

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

Posted on 2003-12-10
3
546 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
Comment Utility
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
Comment Utility
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
Comment Utility
I'm giving you the full points, but I would still like suggestions on how to use VBA instead of VBS.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

728 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

9 Experts available now in Live!

Get 1:1 Help Now