Solved

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

Posted on 2003-12-10
3
566 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
[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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

617 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