Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-12-10
3
Medium Priority
?
580 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

704 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